> y := 2*x^3 + 3*x^2 - 12*x - 7:Here the Maple prompt is the "greater than" sign. The colon tells Maple that the expression has ended. If the colon is replaced by a semi-colon, then Maple will process what you have just typed, and parrot it back to you.
Maple finds roots of equations with the fsolve command. The expression
> r := fsolve(y = 0, x, -5..5);will set r to be the values of x between -5 and 5 for which y = 0. Also try
> r1 := fsolve(y = 0, x, 0..2);Notice that the semicolon MUST follow the command in order for Maple to process the command. If you forget the semicolon, just add it in the next line
> ;and Maple will go ahead and process what preceded.
Maple, unlike Matlab, knows how to differentiate. Suppose we wanted to find the local maxima and minima of y as a function of x. We would set the first derivative of y with respect to x equal to 0 and solve:
> d1 := diff(y,x); d1 := 6x^2 + 6x - 12 > s := fsolve(d1 = 0,x, -5..0);will find one of them, and
> t := fsolve(d1 = 0,x, 0..5);will find the other. To find which is a max and which is a min, use the second derivative test:
> d2 = diff(d1,x); d2 := 12x + 6 > subs(x=s, d2); > subs(x=t, d2);Once again, don't forget the semicolons, or nothing will happen.
The fsolve command can also be used to solve two equations in two unknowns. For example:
> g1 := x^2 - 2*x:
> g2 := y - x:
> fsolve({g1,g2},{x,y});
will return one of the solutions. I'm not sure how to get Maple to find
more than one solution (if more exist), but specifying a search area by
> fsolve({g1,g2},{x,y},{x=1..3,y=1..3});
happens to find the other solution in this case.
The plot command is plot, just as in Matlab, although the syntax is different. Try
> plot(y, x = -3 .. 3);to plot y as a function of x between -3 and 3. The function y and its two derivatives d1 and d2 can be plotted together using
> plot({y, d1, d2}, x = -3 .. 3);
More control over the plot is available. For example, you can print a color
Postscript file from the plot by
setoptions(font=[TIMES,ROMAN,40],thickness=4,scaling=constrained, labels=none,axes=boxed); plotsetup(ps,plotoutput=`file.ps`,plotoptions=`color,noborder,portrait`); plot(y,x = -3..3);Check Maple's help for more options.
Three-dimensional plots are easy. Try
> plot3d(cos(x*y), x = -5 .. 5,y = -5 .. 5);to see an example. You can use the additional options
> plot3d(cos(x*y), x = -5..5,y=-5..5,axes=boxed,color=cos(x*y),style=patch,view=[-5..5,-5..5,-2..2]);Other options to try within the plot3d command are scaling=constrained, which gives a 1-1 aspect ratio, scaling=unconstrained, which makes all 3 axes the same length, and style=patch or wireframe or hidden or patchcontour or patchnogrid. The option orientation = [a1,a2] sets the viewing point at a1 degrees around the origin in the xy-plane (so a1=0 is the x-axis and a1=90 is the y-axis) and a2 degrees down from straight up (a2=0 looks straight down and a2=90 is a view from a point sitting on the xy-plane). Default is orientation=[45,45]. The option color=x^2+y^2 will color the plot according to x^2+y^2.
To create a .jpg file containing a plot, precede the plot command above with
> plotsetup(jpeg,plotoutput=`filename.jpg`,plotoptions=`portrait`);Yes, those are left apostrophes. Once you do this command, you can do a plot, then change the name of the output file by
>plotsetup(plotoutput=`newfilename.jpg`);and proceed with another plot. You can make Postscript files instead by replacing .jpg by .ps in the above instructions.
One of the greatest strengths of Maple is its ability to do symbolic calculations (in the absence of explicit values for the variables). For example, try setting
> v := a*u^2 + b*u + c;If we enter numbers for a, b, and c, we could use fsolve to find the roots of the equation v = 0. However, suppose we want to solve v = 0 for ANY a, b, c. Then use the solve command:
> solve(v=0,u);Try it and see if you recognize the result.
In order to write programs in Maple, put the commands into a file (for example called) proj3.txt. Then use the command
> read `proj3.txt`inside Maple to run the program. The pound sign # in the program comments out the rest of the line, similar to the percent sign in Matlab.