> Can I call func so that it performs the analytic differentiation
> and then substitute for values of x?
Here's one way of doing this:
(%i1) f(x):=diff(x^3,x);
3
(%o1) f(x) := diff(x , x)
(%i2) f(2);
Non-variable 2nd argument to diff:
2
#0: f(x=2)
-- an error. Quitting. To debug this try debugmode(true);
(%i3) f(x):=([tmp:diff(u^3,u)],ev(tmp,u=x));
3
(%o3) f(x) := ([tmp : diff(u , u)], ev(tmp, u = x))
(%i4) f(2);
(%o4) 12
And here's another way:
(%i5) funmake(":=",[f(x),diff(x^3,x)]),eval;
2
(%o5) f(x) := 3 x
(%i6) f(2);
(%o6) 12
Both methods (and there are other ways) ensure that the diff() part gets
evaluated before any values are substituted; in the second example, the
evaluation takes place once, when the function is defined, whereas in the
first case the diff() part is evaluated every time the function is called,
using a dummy variable (u).
Viktor