An Introduction to Maple

This document will introduce a few of the basic commands and techniques for using Maple on RCS. Enter the commands into Maple as you read this document.

To bring up Maple, left click on Maple in the RCS Applications menu or type maple & in a Unix window.

                        
> 1+1;

                           2

     The > is the prompt from Maple to type a command.  All Maple 
     commands end with a semicolon.  This result looks like what we 
     might get from any desk calculator...
 
--------------------------------------------------------------------------------
> x+x;

                          2 x

     ...but Maple can manipulate variables too!
 
--------------------------------------------------------------------------------
> 17!/15^17
> ;

                      3903291392
                   ----------------
                   1081219482421875

 
     The factorial function is denoted ! and ^ raises to a power. If you 
     forget the semicolon, you can put it on the next line.  Notice that 
     Maple always tries to do exact rational arithmetic...
 
--------------------------------------------------------------------------------
> evalf(");

                                 -5
                   .3610082370*10

     
     The evalf command evaluates numerical results as floating point.  
     You can refer to the previous result as ".
     
--------------------------------------------------------------------------------
> y:=x^3 - x**2 - x + 1;

                       3    2
                 y := x  - x  - x + 1

     The assignment operator := causes y to be assigned the value of the 
     expression of the right-hand side.  Exponentiation can be indicated 
     by either ^ or **.
     
--------------------------------------------------------------------------------
     
> subs(x=2,y);

                           3

     The subs command tells what y would be if x were 2, without giving 
     x that value...
> y;

                     3    2
                    x  - x  - x + 1

     ...and without changing the definition of y.
     
> x:=2;

                        x := 2

     If we instead assign x the value of 2...
     
> y;

                           3

     ...then y changes to its corresponding value.
     
> x:='x';

                        x := x

     We can cause x to be regarded as a variable once again by 
     unassigning it...
     
> y;

                     3    2
                    x  - x  - x + 1

     ...and since x is now unknown, y returns to being an expression in 
     terms of x.
     
--------------------------------------------------------------------------------
> solve(y=0,x);

                       -1, 1, 1

     The solve command finds roots analytically if it's possible.
     
--------------------------------------------------------------------------------
> s:=solve(a*x^2+b*x+c=0,x);

                     2         1/2              2         1/2
             - b + (b  - 4 a c)         - b - (b  - 4 a c)
   s :=  1/2 ---------------------, 1/2 ---------------------
                       a                          a           

     When solving the quadratic equation, Maple returns the two 
     solutions in a list that we have called s...
     
> s[1];

                           2         1/2
                   - b + (b  - 4 a c)
               1/2 ---------------------
                             a          

     ...and we can refer to the individual entries of this list using 
     brackets.
     
> s[2];

                           2         1/2
                   - b - (b  - 4 a c)
               1/2 ---------------------
                             a          

--------------------------------------------------------------------------------
> fsolve(x^5-3*x+2=0,x);

             -1.446857248, .7412709106, 1.

     The fsolve command returns all real roots for a polynomial.
     
--------------------------------------------------------------------------------
> sum(k^2,k=1..n);

                  3              2
       1/3 (n + 1)  - 1/2 (n + 1)  + 1/6 n + 1/6

     The sum command is quite useful.
     
--------------------------------------------------------------------------------
> simplify(");

                     3        2
                1/3 n  + 1/2 n  + 1/6 n

     Did you recall this formula for the sum of the squares of the first 
     n integers?
     
--------------------------------------------------------------------------------
> f:=x^(x^x);

                              x
                            (x )
                      f := x    

     Let's consider this harmless-looking function.
     
--------------------------------------------------------------------------------
> subs(x=4,f);

13407807929942597099574024998205846127479365820592393\
37772356144372176403007354697680187429816690342769003\
1858186486050853753882811946569946433649006084096     

     The backslash denotes continuation of the result (in this case, a 
     big integer).
     
--------------------------------------------------------------------------------
> fp:=diff(f,x);

                x  /                         x \
              (x ) | x                      x  |
       fp := x     |x  (ln(x) + 1) ln(x) + ----|
                   \                         x /

     The diff command gives the derivative of f with respect to x.
     
--------------------------------------------------------------------------------
> int(fp,x);

                            x
                          (x )
                         x    

     The indefinite integral of fp is a function whose derivative is fp.
     
--------------------------------------------------------------------------------
> plot(cos(x),x=-Pi..Pi);

     Maple is good at plotting.  This plot will come up in a separate 
     window.  To leave the plot, choose Exit under the File menu in the 
     plot window.  The Appendix of this tutorial contains an example of 
     including a plot in your Maple session.
     
--------------------------------------------------------------------------------
     
     
     Printing Your Maple Session:
     
     To print your Maple session, you must first click on the word File 
     in the upper left-hand corner of your Maple window.  This drops
     down a menu. Click on Print....  A new Page Setup Dialog window will
     appear with an Output to File: field above a Printer Command: field.
     The Printer Command: field contains the default print command, lpr.
     Left click on the diamond button to the left of Printer Command:.
     Then left click on the OK button at the bottom of the Page Setup
     Dialog window. Your Maple session will print on the nearest
     PostScript printer.
    
     The Appendix below includes information on how to save your Maple
     session so that you can restart it at a later time.
     
--------------------------------------------------------------------------------
     
     Quitting Out of Maple:
     
     To quit Maple, enter the Maple command
      
> quit;

     or click on the word Exit in the File menu.
     
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------     
     
                                Appendix:
                          Other Maple Features
     
     
> evalf(Pi);

                      3.141592654

     Maple knows several special constants, whose names you should not 
     use as variables.  This one is Pi, not pi.
     
--------------------------------------------------------------------------------
> evalf(E);

                      2.718281828

     E is the base of the natural logarithms, usually denoted in 
     mathematics by e.
     
--------------------------------------------------------------------------------
> I*I;

                          -1

     Maple uses I for the square root of -1.
     
--------------------------------------------------------------------------------
> evalf(""");

                      3.141592654

     Here the result to be evalf'd is the third one back.  That's as far 
     back as you can refer using the ".
     
--------------------------------------------------------------------------------
> limit(sin(x)/x,x=0);

                           1

     Maple is good at taking limits.  Notice that Maple uses x=0 to 
     denote x approaches 0.
     
--------------------------------------------------------------------------------
> y:=(1+1/x)^x;

                                  x
                    y := (1 + 1/x) 
     
> limit(y,x=infinity);

                          e

     So y approaches e, the base of the natural logarithms, as x 
     approaches infinity.
     
--------------------------------------------------------------------------------
> f:=abs(cos(x));

                   f := abs(cos(x))
     
     Maple uses the abs command for absolute value.
     
--------------------------------------------------------------------------------
> solve(x^3-3*x+9=0,x);

      1/3     1
  -     - -----,
              1/3
            


        1/3      1             1/2 /    1/3     1  \
  1/2     + ------- + 1/2 I 3    |-     + -----|,
                  1/3              |            1/3|
              2                  \             /


        1/3      1             1/2 /    1/3     1  \
  1/2     + ------- - 1/2 I 3    |-     + -----|
                  1/3              |            1/3|
              2                  \             /


                              1/2
 :=             9/2 + 1/2 77   

     Maple sometimes uses substitutions with names like  to make 
     complicated expressions look simpler.  Notice that the above list 
     gives one real root followed by two complex roots (separated by 
     commas).
     
--------------------------------------------------------------------------------
> f:=sin(x^2)/(1+x^2);

                               2
                          sin(x )
                     f := -------
                                2
                           1 + x 

     
> int(f,x);

                      /      2
                     |  sin(x )
                     |  ------- dx
                     |        2
                    /    1 + x    

     Maple cannot find this indefinite integral...
     
> int(f,x=0..1);

                      1
                      /      2
                     |  sin(x )
                     |  ------- dx
                     |        2
                    /    1 + x
                    0             

     ...so it cannot find a closed form expression for this definite 
     integral.
     
> evalf(");

                      .2014627982

     But it can evaluate the above definite integral numerically.
     
--------------------------------------------------------------------------------
> solve(cos(x)=x,x);

     Maple cannot solve this equation analytically, so a null response 
     is returned...
     
> fsolve(cos(x)=x,x);

                      .7390851332

     ...but Maple can solve the equation numerically using the fsolve 
     command.
     
--------------------------------------------------------------------------------
> plot({cos(x),x^2},x=-3..Pi);

     Maple can plot several functions on the same axes. To embed this 
     plot into your Maple session, use the Edit menu in the plot window 
     to Copy... and then use the Edit menu in the Maple window to Paste. 
     You may want to resize the plot (by resizing the plot window) 
     first.
     
     To insert a prompt after the plot, place your cursor in the region 
     of the embedded plot and left click.  This gives a "big" cursor to 
     the left of the plot.  Then left-click on the Insert Prompt entry 
     in the Edit menu.  You can also insert text or a separator line 
     using the same technique.

     We can restrict the range of the y-axis to get a better plot...

> plot({cos(x),x^2},x=-3..Pi,-2..2);

--------------------------------------------------------------------------------
     
     Saving Your Maple Session:
     
     To save your Maple session to a new file so that you can read it in 
     to Maple at a later date, click on the entry Save As... in the File 
     menu.  A Save Session window will appear.  Click on the Selection 
     field, and type in a file name.  (You can specify a directory at 
     the same time by naming it directory_name/file_name.)  This will 
     create a Maple Script file in your home directory (or in the 
     directory you specified).  If you will want all your variables to 
     be set correctly when you read this session back in, which will 
     usually be the case, then "turn on" the button next to the words

               Save kernel state
               
     if necessary, by clicking on the button.  (The button is "off" when 
     light grey and "on" when a darker grey.)  Then click on Save.
     
     To save your Maple session to an existing file, click on Save 
     rather than Save As... in the Maple File menu.  If you loaded the 
     kernel state when you read the file in, then the kernel state will 
     also be saved automatically.
     
--------------------------------------------------------------------------------
     
     Retrieving a Previous Maple Session:
     
     To retrieve a previous Maple Session, click on Open...in Maple's 
     File menu.  A Load Session window will appear.  If you see the file 
     name you want in the Files sub-window, click on it; otherwise, type 
     the file name in the Selection field.  If you want your variables 
     to be set correctly, "turn on" the button next to the words
      
            Load kernel state, if possible
            
     by clicking on it, if necessary.  Then click on Load.
     
--------------------------------------------------------------------------------


Other Maple Topics

Click on an item listed below to access additional information on a variety of Maple-related topics.


Return to the ACS Consulting home page.

Return to the Software page.


Return to ACS home page.


Please send comments and suggestions to

consult@rpi.edu