Session 4.1 Maple programs Part a defining expressions and programs in a session
> restart; A new session
> f1:=sin(z); One expression
> f2:=z^2-1; Another expression
> z:=3.0; f1; f2;
Now we will type in a procedure called trigl
> trigl:=proc(n,x0,dx)
Define
procedure and parameters
local x,k;
Identify
local variables
for k from 1 to n do
Create
loop from 1 to n w/ k as counter
x:=x0+(k-1)*dx;
lprint(x,sin(x),cos(x))
od;
end;
Hit
Return to define program
The program is defined as listed above. Note the punctuation in the program.
There is a semicolon after the definition of x, at the end of the do loop,
and at the end of the program.
Here is an example of the program being called:
> trigl(5,0,0.5);It's not pretty, but it gives five values for sin and cos with the argument starting at 0 and continuing in steps of 0.5.
0., 0., 1.
.5, .4794255386, .8775825619
1.0, .8414709848, .5403023059
1.5, .9974949866, 0.7073720167e-1
2.0, .9092974268, -.4161468365