f := proc(x,y) if x>y then erf(x-y) else erf(y-x) fi end;
But when I try to plot this I get
> plot3d( f(x,y), x=-2..2, y=-2..2 ); Error, (in f) cannot evaluate boolean
Answer: The plot functions have normal evaluation rules. What happens then is that before plot3d is called, is evaluated at symbolic and . I.e. we get
> f(x,y); Error, (in f) cannot evaluate boolean
Maple gives an error because it can't decide if when and have no values. There are two ways of using the plotting commands plot and plot3d as illustrated in the following example for plotting the binomial function.
plot3d( binomial(n,k), n=-3..3, k=-3..3 ); plot3d( binomial, -3..3, -3..3 );
Most users are familiar with the first way, which is to plot a formula in two variables, in this case and . The second way allows you to plot a function given by a Maple procedure or an operator expression. Therefore the solution to the problem is
plot3d( f, -2..2, -2..2 );
Alternatively, one can use quotes to prevent from being evaluated before the plot routine is called thus
plot3d( 'f(x,y)', x=-2..2, y=-2..2 );
Note the frustrated user tried to get around the problem by trying to express this way
f := proc(x,y) if signum(x-y)=1 then erf(x-y) else erf(y-x) fi end;
This avoids the error but produced a different surprise. This ends up always plotting because
> signum(x-y); signum(x - y)
cannot be evaluted to for symbolic and hence the if test always returns false !!
> if signum(x-y) = 1 then true else false fi; false > f(x,y); - erf(x - y)
Note Maple simplified to . The solution again is to simply plot the function directly plot3d( f, -2..2, -2..2 ); Of course, since we could have expressed as a formula
plot3d( signum(x-y)*erf(x-y), x=-2..2, y=-2..2 );