# Summary of Maple operations and CommandsCS 123 - Drexel UniversitySpring 2008

Key Skills Maple Examples Topics to Master Commands of Use Open, create, and save a Maple worksheet. (see File menu) File/Open File/New/Worksheet Mode File/Save Insert and delete execution groups. (see Insert & Edit menus) Insert/Execution Group/Before Cursor Insert/Execution Group/After Cursor Edit/Delete Element Use the Maple help system. (see Help menu) Help/Maple Help ? ?solve ?plot Use special characters. ; (end of command) 2+3; : (suppress output) 2*3: % (previous result) %; # (comment) 3! = 3*2*1;  # Factorials are fun! Reset all variables. Should be use at top of every program restart restart; Assign a value to a variable. := ; x := 0; Unassign a variable. := ''; x := 'x'; Understand how Maple evaluates variables and names. eval a := 2;  b := 1;  a*x + b; eval(%, x=0); Printing Print a decimal integer printf(%d, ); x := 12: printf("There are %d zeroes", x); Print a floating-point number in scientific notation printf(%e, ); x := 12.3: printf("%e is the answer", x); Print a fixed-point number printf(%f, ); x := 12.3: printf("%f", x); Print a string printf(%s, ); s := "Fred!": printf("First name is: %s", s); Create and solve single equations, or expressions solve solve(a*x + b = 0, x);solve(3*y^2 + y/b, y); Create and solve systems of equations. solve solve({x+y=2, x-y=1}, {x,y}); Numerically solve one or more equations fsolve fsolve(sin(x) = x/2, x=1..3); Create 2-D plots of simple expressions. plot plot(x+1, x=0..5); Load the plots package (and other Maple packages). with with(plots); Plot a list of  points in the plane. plots[pointplot] P1 := [1,2];  P2 := [3,4]; L := [P1,P2];  pointplot(L); Plot a curve using an implicit equation. plots[implicitplot] with(plots):eq := y - x = 1; implicitplot(eq, x=0..5, y=1..6); Display multiple plots simultaneously. plots[display] plot1 := plot(x+1, x=0..5); plot2 := pointplot(L);plots[display]({plot1,plot2}); Calculate the arclength (the perimeter of a semi-circle) arclength with(Student[Calculus1]): ArcLength(sqrt(1-x^2), x=-1..1); orStudent[Calculus1] [ArcLength]   (sqrt(1-x^2), x=-1..1); Animate Generate an 2-D animation animate(plot,..) with(plots): animate( plot, [A*x^2,x=-4..4], A=-3..3 ); Generate an 3-D animation animate(plot3d,...) plots[animate]( plot3d, [A*(x^2+y^2),x=-3..3,y=-3..3], A=-2..2); Understand and write Maple expressions which evaluate to true or false. (see ?boolean help page) i = 1; j <= 2; (0 < x) and (x <= 1); x := Pi; type(x, realcons); Understand and write "if" statements, including those with "elif" and "else" clauses. if y := -1; if y = 0 then   print("zero") elif y > 0 then   print("positive") else   print("negative") end if; Loops Write simple "for" loops with a fixed number of iterations. for for i from 1 to 10 do   printf("%d^2 = %d\n", i, i^2); end do; Write nested "for" loops, including those with a variable number of iterations. for for i from 1 to 5 do   for j from i+1 to 5 do     print(i < j);   end do; end do; Write a "for" loop to build up a sequence. for L := []; for i from 1 to 10 do    L := [op(L), i^2]; end do; Write simple "while" loops with a fixed numer of iterations while i := 1; while i <= 10 do    printf("%d^2 = %d\n", i, i^2);    i := i + 1: end do: Implicit Loops Apply a function to every element of a list, producing another list map L2 :=map( (x) -> x^2, [1.1, 2.3, 3.5]); Sum together things referenced by the range of values of a variable. sum L := [1.7, -3.9, 4.5];sum(L[i], i=i = 1..nops(L)); Random Numbers Create a random number generator in Maple. rand coin := rand(0..1);flip := coin();die := rand(1..6);toss := die(); Generate a list of random numbers using a sequence. seq tosses := [seq(coin(), i=1..100)]; Generate a list of random numbers using a loop. for tosses := []; for i from 1 to 100 do   tosses := [op(tosses), coin()]; end do:  # suppress loop output tosses; Calculus Commands Define a function with 2 variables -> f := (x) -> 2*x; f := (x,y) -> 2*x + 3*y; Find the partial derivative diff(expr, variable) diff(2*x^2 + 3*x, x); ONLY returns the symbolic(unevaluated)  expression for the partial derivative Diff(expr, variable) Diff(2*x^2 + 3*x, x); Compute indefinite integrals int(expr, variable) int(sin(x), x); Compute definite integrals int(expr , variable = low .. high) int(sin(x), x=0..Pi); ONLY returns the symbolic (unevaluated) expression for the integral Int(expr, variable)Int(expr , variable = low .. high) Int(sin(x), x);Int(sin(x), x=0..Pi); Find the minimum value of a function minimize(expr, var=a..b); minimize(sin(x), x=0..Pi); Find the maximum value of a function maximize(expr, var=a..b); maximize(sin(x), x=0..Pi); Find a local minimum for for an expression in a interval with(Optimization); NLPSolve(expr, var = a..b); with(Optimization): NLPSolve(x*(5-x), x=0..6); Various useful commands Convert exact results to floating point numbers evalf evalf(Pi); Returns a decimal approximation using 20 significant digits. evalf evalf(Pi, 20); Write a piecewise function piecewise piecewise(x>0, x, -0);piecewise( x <-0, 0, x<=1, .5,     1.0); Simplify the format of an expression simplify simplify(4^(1/2)+3); Convert an expression to factored normal form normal normal((x^2-y^2)/(x-y)^3); Expand the numerator and denominator  (to partially simplify) normal(..,expanded) normal(1/x+x/(x+1),expanded); Math functions Return the minimum of a sequence of numbers. min min(2, 3, 3.7); Return the maximum value max max(2, 3, -47); Return the absolute value abs abs(-3); Calculate the value of e to the power of x exp exp(1); # returns e Find the natural logarithm (lnx) log log(20); Find the common logarithm log10 log10(1000); # return 3 Trigonometric functions (see ?trig, ?invtrig help pages) sin(x), cos(x), tan(x), sec(x) csc(x), cot(x), sinh(x), cosh(x)   tanh(x), sech(x), csch(x), coth(x),arcsin(x), arccos(x), arctan(x),arccsc(x), arcsec(x), arcccot(x),arcsinh(x), arccosh(x), arctanh(x),arcsech(x), arccsch(x), arccoth(x),arctan(y,x) Compute the square root sqrt sqrt(16); Compute powers a^b 5^3, 5^(1/3), 7^(-2), 3.5^b Factorial n! 1000! Summation (definite or symbolic) sum( expr, var = low .. high); sum( i, i=1..10);sum( i^2, i=1..n); Products (definite or symbolic) product( expr, var = low .. high); product( i, i=100..200);product((i+1)/(i+5),i=1..n);
Computation Lab | Department of Computer Science | College of Engineering | Drexel University

This web page was last updated on September 30, 2007.