------------------------------------------------------------------------- PHYS210 2009-10-01 LAB SUMMARY Simple Maple procedures ------------------------------------------------------------------------- 1) Change to your ~/maple directory, and using your text-editor create Maple procedures as follows in the file 'procs' % cd % cd maple % cat maple myadd1 := proc(x,y) x + y end proc; myadd3 := proc(x::algebraic, y::algebraic) x + y end proc; mysum := proc(x::algebraic, y::algebraic, z::algebraic) x + y + z end proc; mysum1 := proc(x::integer, y::integer, z::integer) x + y + z end proc; mysum2 := proc(x::numeric, y::numeric, z::numerica) x + y + z end proc; # Note, myadd1 and myadd3 were defined in today's lecture, # mysum, mysum1 and mysum2 are straightforward extension of myadd3 # # mysum: Returns the sum of its three arguments # Each argument must be of type algebraic # mysum1: Returns the sum of its three arguments # Each argument must be of type integer # mysum2: Returns the sum of its three arguments # Each argument must be of type numeric # Start command-line maple within the directory ~/maple, and # input the procedures using the read command % maple |\^/| Maple 12 (IBM INTEL LINUX) ._|\| |/|_. Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2008 \ MAPLE / All rights reserved. Maple is a trademark of <____ ____> Waterloo Maple Inc. | Type ? for help. > read procs; myadd1 := proc(x, y) x + y end proc myadd3 := proc(x::algebraic, y::algebraic) x + y end proc mysum := proc(x::algebraic, y::algebraic, z::algebraic) x + y + z end proc mysum1 := proc(x::integer, y::integer, z::integer) x + y + z end proc mysum2 := proc(x::numeric, y::numeric, z::numeric) x + y + z end proc # Usage examples: mysum > mysum(a,b,c); a + b + c > mysum(a,b,"foo"); Error, invalid input: mysum expects its 3rd argument, z, to be of type algebraic, but received foo # Usage examples: mysum1 > mysum1(2,100,234); > mysum1(2,100,234.0); Error, invalid input: mysum1 expects its 3rd argument, z, to be of type integer, but received 234.0 # Usage examples: mysum2 > mysum2(2,100,234.0); 336.0 > mysum2(2,a,234.0); Error, invalid input: mysum2 expects its 2nd argument, y, to be of type numeric, but received a