next up previous
Next: The subs command Up: Preliminaries about Maple Previous: The diff (and Diff)

Subsections

The int (and Int) command

Symbolic integrals

The int command is used to compute both definite and indefinite integrals of Maple expressions. Its syntax is basically

> 
  int(f,x);

where f is an algebraic expression and x is the integration variable. For example, to compute

$\displaystyle \int$$\displaystyle {\frac{3x-6}{x^2-4}}$ dx ,

we execute the Maple command

> 
  int((3*x-6)/(x^2-4),x);


\begin{maplelatex}
\begin{displaymath}
3 \ln(x + 2)
\end{displaymath}\end{maplelatex}
Notice that Maple does not provide the constant of integration. You will occasionally have to take this into account and provide your own constant.

You must specify the variable of integration. In expressions involving other parameters, Maple assumes that you want the integral of the expression as the variable you specify changes and that all other parameters in the expression represent constants:

> 
  int(exp(a*x),x); 


\begin{maplelatex}
\begin{displaymath}
\frac{e^{ax}}{a}
\end{displaymath}\end{maplelatex}

To compute a definite integral, the range over which the integration variable moves must be specified:

> 
  int(x^2*exp(x),x=0..2);


\begin{maplelatex}
\begin{displaymath}
2 e^2 - 2
\end{displaymath}\end{maplelatex}

The int command in Maple has a particular behavior in certain situations:

As with diff, there is an inert form Int of the integral command which can be used in combination with int to produce easily readable worksheets:

> 
  Int(ln(1+3*x), x=1..4);


\begin{maplelatex}
\begin{displaymath}
\int _{1}^{4} \ln {(1+3x)}dx
\end{displaymath}\end{maplelatex}

> 
  Int(ln(1+3*x), x=1..4)=int(ln(1+3*x),x=1..4);


\begin{maplelatex}
\begin{displaymath}
\int _{1}^{4} \ln {(1+3x)}dx = \frac{13}{3}\ln{(13)}-3-\frac{4}{3}\ln{(4)}
\end{displaymath}\end{maplelatex}

The inert form Int is also very useful in many situations when you wish to delay the evaluation of an integral, as we shall see below.

Numerical integration

With the evalf command, you can force Maple to apply a numerical approximation technique for definite integration:
> 
  evalf(Int(sqrt(1+x^10),x=0..1));


\begin{maplelatex}
\begin{displaymath}
1.040899075
\end{displaymath}\end{maplelatex}
Notice that the we are using the inert form of the integration command, Int. This prevents Maple from attempting to evaluate the integral symbolically and then applying evalf to the answer. In many cases, this can save a huge amount of time, because Maple will work very hard to try to compute the symbolic form of the integral. For example, approximating $\displaystyle \int_{0}^{1}$esin(x) dx with the command

> 
  evalf(int(exp(sin(x))),x=0..1);

took more than 10 times the amount of time needed to execute

> 
  evalf(Int(exp(sin(x))),x=0..1);

More complicated integrals can have even more dramatic differences.

Approximations through Riemann Sums

Maple can also compute expressions that approximate a definite integral using rectangles, trapezoids, etc. It can also do approximations using Simpson's rule. The only difficulty is that these commands are contained in a separate library called student and you must load this library into computer memory before you can use it:
> 
  with(student):

Once loaded, you can play with it. For example, if you want to use the left sum approximation to an integral, the height of each rectangle is determined by the value of the function at the left side of each interval. You may specify the number of intervals you wish to use. If you do not, Maple will use four intervals by default:

> 
  leftsum(x^4*ln(x),x=1..4,10); 


\begin{maplelatex}
\begin{displaymath}
\frac{3}{10} \left( \sum_{i=0}^9{
(1 + \frac{3}{10} i)^4 \ln(1 + \frac{3}{10} i)}\right)
\end{displaymath}\end{maplelatex}

Maple can also draw pictures of the rectangles used to approximate the integral of a function on a given interval:

> 
  leftbox(1/x,x=1..2,10);

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

The following is the result of using the Simpson's rule for the function xsin(x2) on the interval 1 $ \leq$ x $ \leq$ 5. Since the number of intervals is not specified, Maple assumes four equal intervals by default:

> 
  simpson(x*sin(x^2),x=1..5);


\begin{maplelatex}
\begin{displaymath}
\frac{1}{3}\sin(1) +
\frac{5}{3}\sin(25) ...
...m_{i=1}^{1}{(1+2i) \sin((1 + 2 i^2)^2)}\right)
\end{displaymath}\end{maplelatex}

Multiple integrals

Maple does iterated integrals:
> 
  int(int(x^2*y^3,x=0..y),y=2..3); 


\begin{maplelatex}
\begin{displaymath}\frac{2059}{21}
\end{displaymath}\end{maplelatex}
This is literally an iterated integral: the integral of x2y3 with respect to x on the interval [0, y] is nested inside the integral with respect to y on the interval [2, 3], in effect calculating

$\displaystyle \int_{2}^{3}$$\displaystyle \int_{0}^{y}$x2y3dxdy .


next up previous
Next: The subs command Up: Preliminaries about Maple Previous: The diff (and Diff)

Translated from LaTeX by Scott Sutherland
2002-08-29