I think what you're looking for is define():
(%i1) f(x):=q*x^2+r;
2
(%o1) f(x) := q x + r
(%i2) define(df(x),diff(f(x),x));
(%o2) df(x) := 2 q x
(%i3) df(a);
(%o3) 2 a q
That said, one of your comments suggests that you may always be wanting to
differentiate with respect to the symbolic variable x, so that you don't get
this result:
(%i4) df(x^2);
2
(%o4) 2 q x
In this case, the solution is even simpler:
(%i5) df(x):=diff(f(x),'x);
(%o5) df(x) := diff(f(x), 'x)
(%i6) df(x^2);
3
(%o6) 4 q x
But notice that
(%i7) df(a);
(%o7) 0
since a is not a function of x, and we're always differentiating now with
respect to x.
Viktor
-----Original Message-----
From: maxima-admin@math.utexas.edu [mailto:maxima-admin at math] On
Behalf Of edA-qa mort-ora-y
Sent: Sunday, January 02, 2005 9:50 AM
To: maxima@math.utexas.edu
Subject: Defining derivative functions.
I need a way to define a function and its derivative as functions. That
is, I want to accomplish what one might expect the following would do:
f(x) := q*x^2 + r;
df(x) := diff( f('x), 'x );
But if you do this the x variable in df(x) is in no way related to the x
variable in f(x). If you try this:
df(x) := diff( f(x), x );
It fails as obviously you are differentiating with whatever is passed to
df(x), not the symbolic variable x anymore.
I even tried using an intermediary:
eq : q*x^2 + r;
f(x) := eq;
df(x) := diff( eq, 'x );
But this also didn't work.
So, how do I do this, that is, create a function and then create its
derivative (also as a function).
--
edA-qa mort-ora-y
Idea Architect
http://disemia.com/
_______________________________________________
Maxima mailing list
Maxima@www.math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima