plot2d and quad_qags feeding non-numeric input to user function
Subject: plot2d and quad_qags feeding non-numeric input to user function
From: Charles Russell
Date: Tue, 26 Jul 2011 10:55:08 -0500
I can't use the following user-defined function in the numerical
procedures plot2d and quad_qags because they feed it non-numeric values
as input. In the case of plot2d I can get around this with a discrete
plot, but I can't find a workaround for the numeric integration. (This
is an easy example to integrate analytically, but I am interested in the
general case.)
bell(x):= block([dum],
if not numberp(x) then print("bell: error, x = ",x),
if x <= -1 then dum : 0
else if x >= 1 then dum : 0
else dum : (1 - x^2)^2,
return(dum)
) ;
plot2d(bell, [x,-1,1]); /* OK */
trace(bell);
plot2d(bell(x), [x,-1,1]); /* input non-numerical */
qags_out: quad_qags(bell(s), s, -1, 1); /* input non-numerical */
(%i83) trace(bell);
(%o83) [bell]
(%i84) plot2d(bell(x), [x,-1,1]); /* input non-numerical */
1 Enter bell [x]
bell: error, x = x
1 Exit bell dum
COERCE-FLOAT-FUN: no such Lisp or Maxima function: dum
-- an error. To debug this try: debugmode(true);
(%i85) qags_out: quad_qags(bell(s), s, -1, 1); /* input non-numerical */
1 Enter bell [s]
bell: error, x = s
1 Exit bell dum
COERCE-FLOAT-FUN: no such Lisp or Maxima function: dum
-- an error. To debug this try: debugmode(true);
I've tried converting the input with ev(x,numer) but that doesn't work:
/* lbell(x) := bell(log(x))/x; */
lbell(x) := block(
[xn: ev(x,numer,infeval)],
if not numberp(xn) then print("lbell: error, xn = ",xn),
bell(log(xn))/xn
);
(%i34) plot2d(lbell(x),[x, 0.01, 10]);
lbell: error, xn = x