plot2d and quad_qags feeding non-numeric input to user function
Subject: plot2d and quad_qags feeding non-numeric input to user function
From: Stavros Macrakis
Date: Tue, 26 Jul 2011 14:41:01 -0400
You need to quote the argument:
plot2d( '( bell(x) ), [x,-1,1]);
If quoting weren't required, you couldn't do (e.g.) plot2d(
taylor(sin(x),x,0,3), [x, 0, 3] ) -- Maxima would have no way of knowing
whether you wanted taylor(sin(x),x,0,3) plotted for each value of x (which
would be an error) or the *result* of taylor(...) = x-x^3/6 plotted at each
value of x.
-s
On Tue, Jul 26, 2011 at 11:55, Charles Russell <worwor at bellsouth.net> wrote:
> 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
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>
>