next up previous
Next: The Maple worksheet Up: Preliminaries about Maple Previous: Starting a Maple Session

Subsections

Basic Maple

You can use Maple for numerical calculations, for symbolic manipulations, and for graphing purposes. All Maple commands must be ended with a semicolon ; and the corresponding stroke of the return key. To familiarize yourself with it, try to run the following examples and analyze the results. The commands that you type in and the Maple results are shown here in a way that is similar to what you see on the screen.

Maple for numeric calculations

Most of the time you will be using Maple as a calculator. You can also write programs in Maple, but usually you will be using the tool expecting an immediate response. You type in your statement at the Maple prompt > and Maple responds with an answer:
> 
  1/2+3;


\begin{maplelatex}
\begin{displaymath}
\frac{7}{2}
\end{displaymath}\end{maplelatex}

The symbols for the basic operations are +, -, * and /. Exponentiation is denoted by ^:

> 
  77*(3^5+5^2)/(99-47);


\begin{maplelatex}
\begin{displaymath}
\frac{5159}{13}
\end{displaymath}\end{maplelatex}

In the first example, the inverse of 2 is added to 3. In the second, we input $\displaystyle {\frac{77(3^5+5^2)}{99-47}}$, and Maple computes its value before printing the output.


You must always use the asterisk * for multiplication. Forgetting it in expressions like sin(2*x) or 4*x is easy, and may result in a syntax error message. Even if you don't get a syntax error, Maple will not treat the expression as you expect.

Maple works primarily with whole numbers or fractions. However, you can force it to write the decimal expansion of any number with evalf:

> 
  evalf(100*Pi);


\begin{maplelatex}
\begin{displaymath}314.1592654 \end{displaymath}\end{maplelatex}

> 
  b:=sqrt(2);


\begin{maplelatex}
\begin{displaymath}
\mathit{b} := \sqrt{2}
\end{displaymath}\end{maplelatex}

> 
  evalf(b);


\begin{maplelatex}
\begin{displaymath}1.414213562 \end{displaymath}\end{maplelatex}

> 
  evalf(b,47);


\begin{maplelatex}
\begin{displaymath}1.4142135623730950488016887242096980785696718754 \end{displaymath}\end{maplelatex}

Be careful with this example. The assignment of the variable b to $ \sqrt{2}$ is done with := rather than with =. This will be the case of any other assignment operation you do in Maple, as we discuss below. The equals sign = is used to signify that two things are equal, not to set one to the other.

Notice the difference in the following two examples:

> 
  sum(1/(2*i),i=1..10);


\begin{maplelatex}
\begin{displaymath}\frac{7381}{5040} \end{displaymath}\end{maplelatex}

> 
  sum(1.0/(2*i),i=1..10);


\begin{maplelatex}
\begin{displaymath}1.464484127 \end{displaymath}\end{maplelatex}

In both cases, we compute $ \sum_{i=1}^{10}$(2i)-1. However, in the second case, the presence of 1.0 indicates to Maple the terms in this computation are approximate, and gives you a decimal expansion of the result.

Maple for symbolic manipulations

We can ask Maple to give us a formula for the sum of the cube of the first n integers:
> 
  sum(i^3,i=1..n);


\begin{maplelatex}
\begin{displaymath}
\frac{1}{4} (n + 1)^4 - \frac{1}{2} (n + 1)^3 + \frac{1}{4}(n + 1)^2
\end{displaymath}\end{maplelatex}

We can ask to factor the resulting polynomial in n:

> 
  factor(


\begin{maplelatex}
\begin{displaymath}
\frac{1}{4}n^2(n+1)^2
\end{displaymath}\end{maplelatex}

In this example, Maple's ``ditto operator'' % is used1.3 to refer to the result previously obtained. Thus, in effect, the example above is equivalent to

> 
  factor(1/4*(n + 1)^4 - 1/2*(n + 1)^3 + 1/4*(n + 1)^2);


\begin{maplelatex}
\begin{displaymath}
\frac{1}{4}n^2(n+1)^2
\end{displaymath}\end{maplelatex}


One can expand or factor conveniently:

> 
  p:=(x+1)^4*(x-6)^3;


\begin{maplelatex}
\begin{displaymath}
\mathit{p} := (x + 1)^4 (x - 6)^3
\end{displaymath}\end{maplelatex}

> 
  expand(


\begin{maplelatex}
\begin{displaymath}
x^7 - 14 x^6 + 42 x^5 + 112 x^4 - 287 x^3 - 882 x^2 - 756 x - 216
\end{displaymath}\end{maplelatex}

> 
  factor(


\begin{maplelatex}
\begin{displaymath}
(x + 1)^4 (x - 6)^3
\end{displaymath}\end{maplelatex}


We can use Maple to solve equations (if b still has the value $ \sqrt{2}$ from the previous section, first unassign it by executing the command b:='b'):

> 
  quadeq:=a*x^2+b*x+c;


\begin{maplelatex}
\begin{displaymath}
\mathit{quadeq} := a x^2 + b x + c
\end{displaymath}\end{maplelatex}

> 
  solve(quadeq=0,x);


\begin{maplelatex}
\begin{displaymath}
\frac{1}{2} \frac{-\sqrt{2}+\sqrt{2-4ac}}{a},
\frac{1}{2} \frac{-\sqrt{2}-\sqrt{2-4ac}}{a}
\end{displaymath}\end{maplelatex}
Notice that solve provides both roots of the quadratic polynomial.

Maple also divides polynomials. Here the command you execute has a syntax which is a little bit more complicated. Consider the following example:1.4

> 
  p:=x^10-1; 
  q:=x-1;
  divide(p,q,b);


\begin{maplelatex}
\begin{eqnarray*}
& & \mathit{p} := x^{10} -1 \\
& & \mathit{q} := x - 1 \\
& & \mathit{true}
\end{eqnarray*}\end{maplelatex}

We assign the polynomials x10 - 1 and x - 1 to the variables p and q, respectively, and then ask Maple to divide p by q.1.5Maple replies with the statement true to indicate that the polynomial q = x - 1 divides the polynomial p = x10 - 1 exactly, and places the quotient in the third argument of the divide command. Thus, if you want to know the value of the quotient, you must see what the variable b stands for now:

> 
  b;


\begin{maplelatex}
\begin{displaymath}x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1 \end{displaymath}\end{maplelatex}

Of course, the answer produced by divide will be false if the polynomials do not divide each other exactly. Then one can use the commands quo and rem to find the quotient and remainder of the division:

> 
  r:=x^2+2*x+3;


\begin{maplelatex}
\begin{displaymath}\mathit{r} := x^2 + 2 x + 3 \end{displaymath}\end{maplelatex}

> 
  divide(p,r,c);


\begin{maplelatex}
\begin{displaymath}false \end{displaymath}\end{maplelatex}

> 
  quo(p,r,x);


\begin{maplelatex}
\begin{displaymath}
x^8 - 2 x^7 + x^6 + 4 x^5 - 11 x^4 + 10 x^3 + 13 x^2 - 56 x + 73
\end{displaymath}\end{maplelatex}

> 
  rem(p,r,x);


\begin{maplelatex}
\begin{displaymath}
- 220 + 22 x
\end{displaymath}\end{maplelatex}


We would have obtained an error if we would have tried divide(p,r,b), trying to place the quotient of the division in the variable b: it is no longer a variable since it has a value from the previous example:

> 
  divide(p,r,b);


\begin{maplettyout}
Error, wrong number (or type) of parameters in function divide
\end{maplettyout}
The above command is equivalent to divide(p,r,x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1), which makes no sense at all. If we insist on calling the result of the division b, it would have been necessary to unassign the value of b first:

> 
  b:='b';


\begin{maplelatex}
\begin{displaymath}\mathit{b} := \mathit{b} \end{displaymath}\end{maplelatex}
We could also have done this within the command itself, using divide(p,r,'b').1.6Further discussion on this is given in section 4.2.


We can use solve for systems of equations. For example:

> 
  solve(1*x+(1/2)*y+(1/6)*z =1,
        (1/2)*x+(1/6)*y+(1/24)*z =0,
        (1/6)*x+(1/24)*y+(1/120)*z =1,  x,y,z );


\begin{maplelatex}
\begin{displaymath}\{x = 39, y = -216, z = 420 \} \end{displaymath}\end{maplelatex}

Maple also solves inequalities:

> 
  solve(x^2-4*x-7>0,x);


\begin{maplelatex}
\begin{displaymath}
\mathrm{RealRange}( - \infty ,  \mathrm{...
...ange}(\mathrm{Open}(2 + \sqrt{11}),  \infty )
\end{displaymath}\end{maplelatex}

> 
  solve(abs(1-x^2)<1/2,x); 


\begin{maplelatex}
\begin{displaymath}
\mathrm{RealRange}\left(\mathrm{Open}\lef...
...{Open}\left(\frac{\sqrt{6}}{2} \right) \right)
\end{displaymath}\end{maplelatex}


Graphing in Maple

Let us now use the graphics facilities of Maple. It is quite straightforward to draw the graph of a simple expression. For example, to graph the function sin(x2) over the range -3 $ \leq$ x $ \leq$ 3, we do the following.

> 
  plot(sin(x^2), x=-3..3);

\begin{mfigure}\centerline{ \psfig {figure=BFig1.ps,height=2.4in}}\end{mfigure}

Notice that within the worksheet interface, clicking the right mouse button on the displayed graph causes a menu to pop up that allows you to change some of its properties. Clicking the left mouse button causes a box to appear around the graph and the buttons on the toolbar to change. You can use the box to resize the graph, and the buttons to change attributes such as the style of the axes and the aspect ration.

In section 9 we shall discuss in further detail the graphing features of Maple.



Footnotes

... used1.3
In Maple V release 4 and earlier, Maple used the double-quote " to refer to the result of the previous command instead of %. If you encounter an older Maple program, you might have to change this, among some other things.
... example:1.4
In the worksheet interface, we can insert linebreaks by holding the shift key and the return key simultaneously. Maple does not execute what we type until we hit the return key unshifted.
... q.1.5
Of course, we could have done all of this in a single Maple command divide(x^10-1, x-1, b); if we had no intention of using p or q again.
... divide(p,r,'b').1.6
In both cases, it is very important to use the proper quotation marks; using " or ` means a very different thing, and would not work. The quotation mark used here is the `single quote' or `right quote', and on most keyboards is on the same key as the double quoute, near the enter key.

next up previous
Next: The Maple worksheet Up: Preliminaries about Maple Previous: Starting a Maple Session

Translated from LaTeX by Scott Sutherland
2002-08-29