Session 4.1 Maple programs Part b Loading a previously executed session
We can load the ex1.mws worksheet by using the Open option under the File menu. Note that the Maple worksheet will look exactly like the one that is saved. We can not go to the bottom of the new session and expect the procedures and expressions to be in place. That will only occur after we execute the commands in the session. This can be done by typing a sufficient number of Returns or by using the Edit menu to execute the Worksheet. Here are the commands and comments as they looked at the end of session 4.1a. We can use them as they were saved or modify them to work on more problems. Note that if we did not close the Maple window or execute restart, we would still have the results in place.
> 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 .7073720167e-1
2.0 .9092974268 -.4161468365
> z;
>