I want to use a function’s derivative in an other function. How should this be done in Maxima?
E.g:
f(x) := 2*x^4;
g(x) := diff(f(x),x)-8;
Now g(x) yields 8x^3-8 as expected, but g(0) gives an error, since diff(f(0),0) doesn’t make sense. But then how should I properly define g?
Michael’s answer is good, but it does the differentiation everytime
g(x)is called. (Also, normally you see it wrapped in ablockstatement to ensure thatyis properly localized).There is a way to force the RHS to evaluate at the time of definition
and with the general
x.The syntax is
Compare with the block construct:
Notice (%o4) which shows that the RHS is unevaluated.
Ref: http://www.math.utexas.edu/pipermail/maxima/2007/004706.html