A MAPLE tutorial

List of useful functions

diff(func(x),x); take the derivative of func(x).

int(func(x),x); obtain the integral of func(x).

with(plots): plot(func(x),x=lower..upper); plot func(x) from the given lower bound to the upper bound.

evalf(func(x)=0); return a numerical evaluation (like a calculator).

simplify(func(x)); factor and simplify an expression.

expand(func(x)); expand an expression.

subs(x=[a numeric],func(x)); substitute in a numeric value into a function.

fsolve(func(x),x); find the roots (zero crossings) of the given function of x.

General rules

1. Commands must end in a semi-colon.

2. Inside a function fields of information are separated by a comma.

3. Plot limits and integration limits are separated by two periods.

4. Function calls can be combined.

 

Examples:

evalf(subs(x=[a numeric],func(x))); returns a floating point number after substituting in a numeric value into a function.

 

fsolve(diff(func(x),x); find the roots of a function of x after taking its derivative.

 

Integration and Differentiation

To take the derivative of I0(a) = sqrt(p/a) with respect to a.

At the MAPLE prompt type:

>diff(sqrt(Pi/a),a);

Note that MAPLE did not simplify this and I had to simplify it myself. Here even the simplify command will not write it exactly in the form I want.

To take the second derivative of I0(a) with respect to a you must plug the answer from part one (i.e. the right hand side of the answer given above).

 

>diff((-1)^2*(1/2)*sqrt(Pi/a^3),a);

Alternatively I could have used diff twice.

> diff(diff(sqrt(Pi/a),a),a);

I would have then obtained an answer that has the form:

Note that when a solution appears in MAPLE you can cut and paste it into another expression. For example, if I grab this text and use cntrl c I can paste the following text

-1/4/(Pi/a)^(3/2)*Pi^2/a^4+1/(Pi/a)^(1/2)*Pi/a^3

into the simlify function.

> simplify(-1/4/(Pi/a)^(3/2)*Pi^2/a^4+1/(Pi/a)^(1/2)*Pi/a^3);

Alternatively, to obtain a simplified form of this expression I use:

> simplify(diff(diff(sqrt(Pi/a),a),a));

 

Integration can be exemplied using an exponential integral.

> int(exp(-a*r),r);

This returns the indefinite integral.

 

To obtain the definite integral use the limits. For example, to integrate from zero to infinity use:

> int(exp(-a*r),r=0..infinity);

Note that we can write out infinity.

MAPLE returns a somewhat complicated message

Definite integration: Can't determine if the integral is convergent.

Need to know the sign of --> a

Will now try indefinite integration and then take limits.

This message means that without knowing the sign of a it will give you a limit expression which you can evaluate yourself. Here if a were negative this expression would be infinity. However, we are only interested in positive values of a for which we have:

 

We continue our examples using Gaussian integrals can be written in the form:

Transform to spherical polar coordinates recognizing that

x = r sinq and y = r cosq.

 

To evaluate this we use the substitution u = r2 again so that du = 2rdr. The radial part is trivial using the formula.

However, the trig part is a little difficult. So use the int() command. First let’s use the indefinite integral.

At the MAPLE prompt type 

>int(cos(t)^2*sin(t)^2,t);

-1/4*sin(t)*cos(t)^3+1/8*cos(t)*sin(t)+1/8*t

Or we can get a numerical result if we like using the command

>int(cos(t)^2*sin(t)^2,t=0..Pi/2);

1/16*Pi

Notice that the limits are entered as x=lower..upper with two dots inbetween the lower and upper limit.

This leads to the following answer.

 

To obtain the result for v = 2 by integration

Using the same protocol as above for I0(a) we obtain the square in two dimensions

 

Making the same substitution of variable for polar coordinates

And the radial part can be solved analytically and easily by techniques you are now familiar with.

Now, for the angular terms in the I2(a) integral, the indefinite integral is: 

>int(cos(t)^4*sin(t)^4,t);

-1/8*sin(t)^3*cos(t)^5 - 1/16*sin(t)*cos(t)^5 + 1/64* sin(t)*cos(t)^3 + 3/128*cos(t)*sin(t) + 3/128*t

and the definite integral is:

>int(cos(t)^4*sin(t)^4,t=0..Pi/2);

3/256*Pi

Plotting functions

Plotting the particle in a box wave functions.

You must always type:

>with(plots):

in the MAPLE session in order to use the plot command.

For a box of length 1 the energy levels are n2h2/8m. If we plot in units of m = 1 and h = 1, then energy levels are 1/8 for n=2, 4/8 (i.e. ½) for n=2, 9/8 for n=3 etc.

The wavefunction is:

 

To plot just the first wave function from 0 to 1

>plot(1/8+0.4*sin(3.1416*x)^2,x=0..1);

To include an x-axis label use the following syntax.

>plot(1/8+0.4*sin(3.1416*x)^2,x=0..1,labels=[length,E],labelfont=[TIMES,ROMAN,16]);

To plot several solutions on the same plot use the syntax below. The functions are in {} and separated by commas. Notice that I scaled the normalization prefactors to get these to look good on the plot.

>plot({1/8+0.4*sin(3.1416*x)^2,4/8+0.5*sin(2*3.1416*x)^2,9/8+0.5*sin(3*3.1416*x)^2,16/8+0.5*sin(5*3.1416*x)^2,25/8+0.5*sin(5*3.1416*x)^2},x=0..1,labels=[length,E],labelfont=[TIMES,ROMAN,16]);