Frequently Asked Questions about Maple

The following are questions that have been submitted to the ITC Research Computing Support Group email address res-consult@virginia.edu concerning the technical computing software Maple.

  1. How you can get maple to identify critical points and inflection points on a graph?

  2. How can I get a postscript printout of a Maple plot?

  3. How do I use the Maple I/O commands 'read' and 'save'?

  4. Once I have obtained a solution using the 'solve' command, how do I access the solution variables for further manipulation?
  5. How can I use nested do loops to generate a data set and then plot it?

  6. Is it possible to use a Taylor's expansion in calculations like a polynomial?

  7. How can I plot a two-dimensional Gaussian density function (symmetric in x and y, zero mean, and variance one)?

---

How you can get maple to identify critical points and inflection points on a graph?

I defined a function "a" in Maple:
   a:=x^3-3*x^2+4.
I took the 1st and 2nd derivative of a, calling them "b" and "c".
   b:=diff(a,x); 
   c:=diff(b,x);

Then b and c need to be set to 0 to get the critical values of x.
   solve(b=0,x);
   solve(c=0,x);

This yielded the 3 critical valuse for x=0,1,2.

Now to let Maple solve the function a at 0, 1, and 2:
   x:=0;   
   a;
   x:=1;   
   a;
   x:=2;   
   a;

This yielded the 3 points (0,4), (1,2) and (2,0).

In order to do the plots, set x back to x with the command:

   x:='x'; 

Bring in the "plots" package which lets you plot 2 functions on one
graph:

   with(plots);

Define the 2 functions as "p" and "q":
   p:=plot(a,x=-2..3);
   q:=plot([0,4,1,2,2,0],style=POINT,symbol=BOX);

Graph them both:

   display([p,q]);

DATE:  2-12-98

return to top

How can I get a postscript printout of a Maple plot?

A way to get a printout of your plot from Maple is to issue the
command (in Maple):

   plotsetup(postscript);

then issue your plot command.

The file "postscript.out" will be created in whatever directory you
issued the "xmaple" command.  You can then view the postscript.out file
with ghostview or print it to a PostScript printer with the command lpr.

DATE: 6/5/96

return to top

How do I use the Maple I/O commands 'read' and 'save'?

The syntax of the save command is

   save`somefile.m`;

and this will save the internal state of your current maple session
(including all variable definitions) in a binary (machine readable)
format. If you want to transfer this file by ftp to another machine,
you should do the transfer in binary (as opposed to ascii) mode. This 
file can then be read into a new maple session with the command

   read`somefile.m`;

and all the previous variable definitions will take effect. If the syntax 
of the save is

   save`somefile`;

then the state of the current seesion will be saved as ascii (human readable)
format, can be transferred by ftp in ascii mode and is read into a new
maple session with the command,

   read`somefile`; 

DATE: 6/5/96

return to top

Once I have obtained a solution using the 'solve' command, how do I access the solution variables for further manipulation?

You can use the 'assign' command to set the values of the
solution equal to the corresponding variables, e.g.


> sol:=solve({2*x-4*y+z=-1, 3*x+y-2*z=3, -5*x+y-2*z=4},{x,y,z});

                                  51                    15
                   sol := {z = - ----, x = -1/8, y = - ----}
                                  28                    56

> assign(sol);
> z;

                                        51
                                     - ----
                                        28

> x;

                                      -1/8

> y;

                                        15
                                     - ----
                                        56
   

DATE: 10/28/96

return to top

How can I use nested do loops to generate a data set and then plot it?

The following example shows one way to do the above operations.

#Create X and Y arrays
> restart;
> Y:=array(0..100);
> Y_temp:=array(0..100);

#Initialize Y array
> for i from 0 to 20 do
> Y[i]:=0.9;
> od:
> for j from 21 to 100 do
> Y[j]:=0.2;
> od:
> x:=0.01;
> tau:=0.05*(x^2);
> R:=tau/(x^2);

#Generate values for Y array
> for k from 1 to 10 do
>     Y_temp[0]:=Y[0]*(1-2*R) + 2*R*Y[1];
>     for n from 1 to 99 do 
>     Y_temp[n]:=Y[n] + R*(Y[n+1] -2*Y[n] + Y[n-1]);
>     od;
>     Y_temp[100]:=Y[100]*(1-2*R) + 2*R*Y[100];
> for m from 0 to 100 do
> Y[m]:=Y_temp[m]; 
> od;
> od:

#Generate values for X array
> X:=array(0..100);
> for p from 0 to 100 do 
> X[p]:=.01*p;
> od:

#Convert X and Y arrays to lists, merge and plot.
> Y1:=convert(Y,'list');
> X1:=convert(X,'list');
> pair:=(x,y)->[x,y];
> P:=zip(pair, X1, Y1);
> plot(P);

DATE:  2-12-98

return to top

Is it possible to use a Taylor's expansion in calculations like a polynomial?

Maple has trouble knowing what to do with the higher-order residual terms.
I think the way around this is to convert the series to polynomials and then
combine them, letting the higher-order terms be implicit. The following works.

> a1:=taylor(c(2*x),x=0,6);
> a2:=taylor(c(-x),x=0,6);

> b1:=convert(a1,polynom);
> b2:=convert(a2,polynom);
> a3:=b1+b2;


DATE: 12-17-97

return to top

How can I plot a two-dimensional Gaussian density function (symmetric in x and y, zero mean, and variance one)?

Here is a Maple code example for generating the grid and contour plots of a 
2-D Guassian density function assuming zero means and unit variances. When 
I defined the 2X2 correlation matrix R, I further assumed E[xy]=0.6.

with(linalg):
R:=array( [[1.0,0.6],[0.6,1.0]] );
f := (x,y) -> evalf( 1/(2*Pi) * 1/sqrt(det(R)) * exp(-1/2 * (evalm([x,y] &* 
inverse(R) &* [x,y]) )) );
with(plots):
plot3d(f(x,y), x=-3..3, y=-3..3, grid=[30,30], axes=FRAME);
contourplot(f(x,y), x=-3..3, y=-3..3, grid=[30,30], axes=FRAME);

DATE: 03-17-99

return to top

---

© 2008 by the Rector and Visitors of the University of Virginia.

The information contained on the University of Virginia’s Department of Information Technology and Communication (ITC) website is provided as a public service with the understanding that ITC makes no representations or warranties, either expressed or implied, concerning the accuracy, completeness, reliability or suitability of the information, including warrantees of title, non-infringement of copyright or patent rights of others. These pages are expected to represent the University of Virginia community and the State of Virginia in a professional manner in accordance with the University of Virginia’s Computing Policies.