simple derivative function question



On 1/17/07, sen1 at math.msu.edu <sen1 at math.msu.edu> wrote:
>   I want to consider derivatives as functions.
> (%i14) f(x):= diff(x^3,x);...
> How does one define the derivative as a function, so one can compute
> values, plots, etc?

Presumably you only want to calculate the derivative once, not on each
function call. You can do this using the ''(...) construction (that's
two single-quotes, not one double-quote), which evaluates its contents
when the expression is read.

Examples:

ddd(x):=''(print(x));
x                                             The x is printed during
function *definition*, not evaluation
           =>      ddd(x) := x     This is the resulting definition,
which has no "print"

eee(x):=''(diff(x^3,x));
             =>  eee(x):=3*x^2            Resulting definition

You can also calculate the formula first:

fff: diff(x^3,x);
  => 3*x^2
ggg(x):=''fff => ggg(x):=3*x^2
ggg(2) => 12

I trust this is what you had in mind.

               -s