Subject: Cannot use "diff" in a function assignment.
From: Daniel Carrera
Date: Wed, 23 Nov 2011 23:52:49 +0100
Hi Michael,
On 11/23/2011 11:37 PM, Michel Talon wrote:
> maxima functions are very bizarre objects, in particular evaluation is
> considerably deferred. In the case above i think that df(x) remains
> diff(f(x),x) unevaluated, so that when you compute df(2) you get
> diff(f(2),2) producing the error message you see: the second argument of diff
> is 2 and not a variable.
I see... weird.
Is it possible to force Maxima to evaluate diff(f(x),x) ? I just tried
using "ev" and "expand", but neither one worked.
> I think this is because maxima functions are represented internally by mdefine
> which is "defined" via defmspec, a device which doesn't evaluate the
> arguments. This causes all sorts of problems when you want to do anything non
> trivial with maxima functions. Using expressions is far easier. For example if
> you write
> (%i11) y: df(x);
> 2
> (%o11) 3 x + 4 x + 1
> (%i12) y,x=2;
> (%o12) 21
My problem is very simple. I want to find a polynomial that meets a set
of conditions:
-----------------------
m(x) := a3*x3 + a4 * x4 + a5 * x5 + a6 * x6 + a7 * x7;
define(dm(x), diff(m(x),x));
define(F(x), expand(m(x)/x2));
define(dF(x), diff(F(x),x));
define(ddF(x), diff(dF(x),x));
linsolve( [m(1)=1, dm(1)=0, ddF(1)=6, m(1/2)=5/6, dm(1/2)=10/9],
[ a3, a4, a5, a6, a7 ] );
-----------------------
How would you have done this using expressions? It's not obvious to me
how that would work.
> plot passes the functions to be plotted via coerce-float-fun which does all
> sorts of contortions to evaluate the maxima functions. The typical invocation
> which does that in plot.lisp looks like:
> (catch 'errorsw
> (,float-fun
> (maybe-realpart (mapply ',expr (list , at gensym-args) t))))))
> Besides using new arguments to the functions this runs mapply which is a
> fundamental maxima evaluation procedure, takes the real part of the result if
> it is complex and coerces the result to float. I suppose linsolve does
> something similar i have not checked.
Sounds complicated. I don't understand why evaluating procedures is so
difficult. To my naive mind, it sounds like something simple.
Cheers,
Daniel.
--
I'm not overweight, I'm undertall.