Session 4.1 Maple programs Part a defining expressions and programs in a session and saving the session

> restart; A new session

> f1:=sin(z); One expression

[Maple Math]

> f2:=z^2-1; Another expression

[Maple Math]

> z:=3.0; f1; f2;

[Maple Math]

[Maple Math]

[Maple Math]

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

[Maple Math]
[Maple Math]

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   .7073720167e-1

2.0   .9092974268   -.4161468365

> restart;

In the File menu we used Save As to save this as the session ex1.mws before the restart command was executed. We can then start a new session where we load the ex1.mws worksheet.