Cannot use "diff" in a function assignment.



I started writing an answer to the "philosophical" question, and realized
that I really couldn't do it justice without spending some time with it.  I
disagree with Michel that Maxima defined functions are "very bizarre
objects".  They are simply standard programming functions (a.k.a.
subroutines); mdefine semantics are standard programming function
definitions.  They are NOT, and are not intended to be, "mathematical"
functions.  For better or worse, though, they share the same syntax, so we
have both print(3) and sin(3), though those are really very very different
concepts. Not to mention diff(f(x),x), which again shares the same syntax,
but acts rather differently.

The quick answer is: Maxima is not designed to handle mathematical
functions like f(x)=a*x using the function definition mechanism.

As for

> Is it possible to force Maxima to evaluate diff(f(x),x) ?  I just tried
using "ev" and "expand", but neither one worked.

What do you mean by "evaluate diff(f(x),x)"?  Do you mean "determine the
symbolic derivative of f(x)?"  Or do you mean "determine the value of the
derivative at a particular value"?  I think you mean the latter.

Though it is possible to do all this using the function syntax, it really
works much better to use expressions.

The answer to your problem is very simple -- just don't fight the Maxima
approach:

m: a3*x3 + a4 * x4 + a5 * x5 + a6 * x6 + a7 * x7;
dm: diff(m,x);
F: m/x2;
dF: diff(F,x);
ddF: diff(dF,x);

linsolve( [subst(1,x,m)=1, subst(1,x,dm)=0, subst(1,x,ddF)=6,
subst(1/2,x,m)=5/6, subst(1/2,x,dm=10/9],
         [ a3, a4, a5, a6, a7 ] );

Re: "Sounds complicated. I don't understand why evaluating procedures is so
difficult. To my naive mind, it sounds like something simple."

I don't understand why you are studying the code of coerce-float-fun.  But
the short answer is: users expect many things to be "automagic", and that
gets hard.  Users generally don't want to think about things like variable
scope, for example.

            -s



On Wed, Nov 23, 2011 at 17:52, Daniel Carrera <dcarrera at gmail.com> wrote:

> 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.
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>