On Sun, Jan 02, 2005 at 03:49:41PM +0100, edA-qa mort-ora-y wrote:
> 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).
>
>
I can't give exact refference, but I had asked a similar
question in the past, and the kind folks in this list gave
several ways to do this. The one I remember is to use
"define" for example
(%i49) f(t):= t^2*sin(t);
2
(%o49) f(t) := t SIN(t)
(%i50) define(df(t),diff(f(t),t));
2
(%o50) df(t) := 2 t SIN(t) + t COS(t)
This was 2 or 3 months ago. If you search the list for
"derivative as a funtion" you'll find that discussion.
Nikos