Re: Mupad: Plot problem "Can't evaluate to boolean"



Marten wrote:

your solutions is working well, but I do not understand why. I read

d_f:=(f,k,g)->(if d_h(f,k)>(g-f) then g*d_h(f,k)/(d_h(f,k)-(g-f*10^-3))
else 10000 end_if):

So when you type d_f(f, 5.6, g), you are asking for

if d_h(f, 5.6) > (g-f) then ... alse 1000 end_if

with *symbolic* f and g. MuPAD cannot decide the condition inside the if, so it raises an error. One way around this is to stop MuPAD from using the definition of d_f too early, which is what hold() is doing. Another one would be to use piecewise instead of if, as in

d_f := (f,k,g) -> piecewise([d_h(f,k) > g-f, g*d_h(f,k)/(d_h(f,k)-(g-f*10^-3))],
[TRUE, 1000])


where I used the fact that the branches of piecewise are checked in order, so a “TRUE” in the last condition means ”otherwise”.

A third way, which may or may not be the same (I'm just guessing here) would be

d_f := (f, k, g) -> min(g*d_h(f,k)/(d_h(f,k)-(g-f*10^-3)), 1000):

For generic functions which are going to be reused, the idiom looks a bit more involved, but is really almost always the same:

d_f := proc(f, k, g)
       begin
         // all args numerical?  (works only for real args this way)
         if map({args()}, domtype@float) <> {DOM_FLOAT} then
           return(procname(args())); // no, return unevaluated call
         end_if;

         if d_h(f, 5.6) > g - f then
           ...
         end_if;
       end_proc:


p56n does not need hold() since no if-condition is involved.


regards, Christopher Creutzig .



Relevant Pages