Subject: Cannot use "diff" in a function assignment.
From: Daniel Carrera
Date: Wed, 23 Nov 2011 23:39:37 +0100
Thanks.
Is there a reason why it is like that? It seems very strange to type
"subst([x=3],f)" for what is conceptually a function call.
Another question: When you write:
define(df(x), diff(f(x),x))$
What does the "$" mean? The 'define' call seems to work without it... In
fact... the "$" seems to simply suppress output. Is that all it does?
Is there a reason why I shouldn't use the "define" method? It looks
clearest to me, and it seems to work well. This is my program:
-----------------------
m(x) := a3*x^3 + a4 * x^4 + a5 * x^5 + a6 * x^6 + a7 * x^7;
define(dm(x), diff(m(x),x));
define(F(x), expand(m(x)/x^2));
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 ] );
-----------------------
If I were to rewrite this using 'substr([x=1],dm)=0' I think the result
would be very hard to read.
Cheers,
Daniel.
On 11/23/2011 11:15 PM, Stavros Macrakis wrote:
> This is a difficult point for many new users.
>
> It appears that you want to define a mathematical function f and then
> define a mathematical function df which is df/dx. The simplest and most
> Maxima-like way of doing this is NOT to use use function-definition (which
> is really subroutine-definition). You'd do it something like this:
>
> f: x^3 + 2*x^2 + x - 1;
> df: diff(f,x)$
>
>
> Now to get the value of f at a given value, you'd do subst([x=3],f); for
> df, subst([x=3],df). Another way is ev(f,x=3) and ev(df,x=3), but I don't
> recommend that (long discussion).
>
> Another approach, if you really want to define subroutines, is:
>
> f(x) := x^3 + 2*x^2 + x - 1;
> define(df(x), diff(f(x),x))$
>
>
> Now you can write f(3) and df(3).
>
> Another way to write the "define" is
>
> df(x) := ''(diff(f(x),x))$
>
> but I don't recommend that. In particular, it won't work as you expect
> within programs.
>
> Note that in BOTH approaches above, if you redefine f, it will not redefine
> df!
>
> Well, if I go on, I think I will make things more rather than less
> confusing....
>
> -s
>
>
>
> On Wed, Nov 23, 2011 at 16:53, Daniel Carrera<dcarrera at gmail.com> wrote:
>
>> Hello,
>>
>> I'm pretty new to Maxima and I wonder why the following doesn't work:
>>
>> (%i1) f(x) := x^3 + 2*x^2 + x - 1;
>> (%o1) ...
>>
>> (%i2) df(x) := diff( f(x), x )
>> (%o2) ...
>>
>> (%i3) df(2);
>> diff: second argument must be a variable; found 2
>>
>>
>>
>> I don't understand why this is a problem. It seems like a fairly natural
>> thing to want to do - differentiate a function and use the result as a new
>> function. Strange, because I seem to be able to use diff(f(x),x) in other
>> similar contexts:
>>
>> (%i4) linsolve( [diff( f(x),x) = 2], [x] );
>> (%o4) [ x = 1/4]
>>
>> (%i5) plot2d( diff(f(x),x), [x,-1,1] );
>> (%o5)
>>
>>
>> Any ideas?
>>
>> 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>
>>
>
--
I'm not overweight, I'm undertall.