Debugging.mws

Debugging

Common problems encountered by students and their cures are collected here. You probably came here from a chapter in the text looking for help and will want to go back when you are finished. Here are hyperlinks to take you back to the start of each chapter.

Introduction
Chapter 1: Getting started
Chapter 2: Plotting

Chapter 3: Calculus
Chapter 4: Complex numbers
Chapter 5: Linear Algebra

Chapter 6: Solving equations
Chapter 7: Differential equations
Chapter 8: Programming

Chapter 9: Symbolic algebra

A. Online help

If things go wrong the first thing you should try is online help. This will not always solve your problem, but it a good place to start.

B. Unexpected results

1. If your problem is that you got an answer, but it isn't what you expected, quite often the trouble is that Maple thinks a variable can be anything, but you were thinking that it was a real number. The fix for this is

assume(x,real,y,real,...)

so that Maple will know the same things about the variables that you know. However: watch out for this problem: once you have used assume on a variable, however, you may have trouble having Maple give you numbers. The trouble happens when you assume something about a, use a in an expression which is assigned to another variable (say b), then give a value to a, and finally try to evaluate b. Observe:

> restart;

> assume(a,real);

> b:=cos(a);

b := cos(a)

> a:=2.;

a := 2.

> evalf(b);

cos(a)

2.

Now watch what happens to the same without the assume

> restart;

> b:=cos(a);

b := cos(a)

> a:=2.;

a := 2.

> evalf(b);

-.4161468365

>

I suppose that the lesson here is only to use assume when absolutely necessary and to be aware that

this problem exists.

2. Another common problem is with = vs :=. If you use = when you really mean assign ( := ) you will find that the variable to which you thought you had assigned something doesn't have anything in it.

3. Maple says it has been given an illegal character, but you don't see anything wrong with the line. (a) Look for what looks like a leading space in the command, i.e., for a space betweeen > and the first character of the command. Delete this space. (b) If the problem persists, delete the entire line and retype it.

4. You get the message Error, ';' unexpected . Check your parentheses, they might not be balanced.

Here is a list of other common errors by category and how to fix or work around them. When you find things that drive you crazy in Maple, please email me and I will put them in this section for the benefit of other students. (ross_spencer@byu.edu)

C. Plotting Errors

empty plot

Syntax mistake when plotting an expression. For instance if we have

> restart;

> g:=sin(x);

g := sin(x)

> plot(g,0..5);

Plotting error, empty plot

we get the empty plot error. The correct syntax for plotting an expression is

> plot(g,x=0..5);

[Maple Plot]

or even

> plot(g(x),x=0..5);

[Maple Plot]

axes appear, but no function is plotted

This happens when an expression, function, or procedure is to be plotted, but a parameter that needs to be assigned a value doesn't have one. For instance if we have a function f, an expression g, and a procedure p like this

> restart;

> f:=x->sin(x*t);

f := proc (x) options operator, arrow; sin(x*t) end...

> g:=sin(x*t);

g := sin(x*t)

> p:=proc(x)

> global t;

> sin(x*t);

> end;

p := proc (x) global t; sin(x*t) end proc

then all three of these plot commands give a zero plot

> plot(f(x),x=0..5);

[Maple Plot]

> plot(g,x=0..5);

[Maple Plot]

> plot(p,0..5);

[Maple Plot]

The cure is to assign a value to t, like this

> t:=5;

t := 5

Now all three plot commands will work.

Error, (in plot) invalid arguments

Perhaps you are trying to plot with a variable that has been assigned a value, like this

> restart;

> g:=sin(x);

g := sin(x)

> x:=5;

x := 5

> plot(g(x),x=0..5);

Error, (in plot) invalid arguments

The cure is to undo the assignment like this (the single quotes are important)

> unassign('x');

or

> x:='x';

x := 'x'

then try the plot again.

Error, (in plot/transform) cannot evaluate boolean: -5.*z < -4

Perhaps you have used = instead of := in giving a variable a numerical value; in any case the problem is that z doesn't have a value. This is an especially subtle error when the thing that doesn't have a value is pi , which happens when you use pi instead of Pi.

Parametric plot gives two plots instead

This happens when you get the square brackets in the wrong places. Here is a two-function plot

> plot([sin(s),cos(s)],s=0..2*Pi);

[Maple Plot]

and here is a parametric plot

> plot([sin(s),cos(s),s=0..2*Pi]);

[Maple Plot]

Look carefully at the placement of ] in these two cases.

>

Function plotting fails

When you have defined a function f(x), you try to plot it with plot(f(x),x=0..5) , and it fails, try operator form instead:

> f:=x->fsolve(t=x/(1+exp(t)),t);

f := proc (x) options operator, arrow; fsolve(t = x...

This syntax fails:

> plot(f(x),x=0..2);

Error, (in fsolve) x is in the equation, and is not solved for

This syntax works:

> plot(f,0..2);

[Maple Plot]

>

D. Differentiation errors

Error, wrong number (or type) of parameters in function diff

Same thing as the unassign problem above in Plot errors, only in diff.

> restart:x:=5;

x := 5

> diff(sin(x),x);

Error, wrong number (or type) of parameters in function diff

You need to unassign x.

E. Integration errors

Error, (in int) wrong number (or type) of arguments

Same thing again as the unassign problem in Plot errors, except with int .

> restart:x:=5;

x := 5

> int(sin(x),x);

Error, (in int) wrong number (or type) of arguments

You need to unassign x.

F. Solve errors

Nothing comes back

Sometimes Maple can solve a system if the coefficients are rational numbers, but not if they are floating point numbers. So don't use x*0.01 -- use x/100 instead.

G. Dsolve errors

H. Algebra errors

Error, too many levels of recursion or Warning, recursive definition of name

You have somehow set a variable equal to a function of itself. Here is a simple way to get this error

> x:=1+x;

x := 6

but you can get it indirectly too if there is a chain of assigned variables and you close the chain on itself. It is helpful to know what variables are assigned to what, and you can find this out with the command anames() , unless the system is so messed up from the error that you get garbage. If this happens a restart is in order.

You want x to be a variable, but it is a number instead

x was previously assigned a value and you now need it to be a variable again. Here's a way to fix it.

> x:='x';

x := 'x'

I. Miscellaneous errors

Error, (in assign) invalid arguments

Probably you tried to unassign a variable which was assigned a value and you didn't use single quotes, like this

> restart;x:=5;

x := 5

> unassign(x);

Error, (in unassign) cannot unassign `5' (argument must be assignable)

> unassign('x');

Note that you can also unassign with this command

> x:='x';

x := 'x'

>

Go to top of Debugging