Reputation: 263
I try to define the derivative of the standard normal pdf in terms of the function:
φ(x) := exp (-x^2/2)/sqrt(2 * %pi);
gradef(φ(x),-x*φ(x));
but if I type then:
diff(φ(x),x);
I get:
-(x*%e^(-x^2/2))/(sqrt(2)*sqrt(%pi))`
not as I want -x*φ(x)
.
What I am doing wrong?
Thanks do not
Karl
EDiT :
Unfortunately both suggestions do not work.
Upvotes: 2
Views: 413
Reputation: 17573
I think there's nothing wrong; Maxima is just evaluating phi according to the definition you gave when you call gradef
.
I can think of a couple of things to try. (1) Call gradef
before defining phi. Then maybe you'll get phi in the output when you call diff
. Not sure if that will work.
(2) Define the gradef
using a noun expression, i.e., gradef(φ(x),-x*'φ(x))
. Notice the single quote mark '
before φ(x)
; that makes a so-called noun expression in which the argument x
may be evaluated but the function φ
is not called. Later on in order to evaluate the function, when you want to, you can say ev(someexpression, nouns)
to evaluate all noun expressions in someexpression
.
EDIT: Here's another idea. This works for me. The previous ideas didn't work because φ gets evaluated too soon; this new idea goes to a greater length to prevent evaluation. Note that the gradef is defined for 'φ(x)
, so you have to write diff('φ(x), x)
in order to apply the gradef.
(%i12) gradef('φ(x), -x*'φ(x));
(%o12) φ(x)
(%i13) diff('φ(x), x);
(%o13) - x φ(x)
The gradef produces a noun expression -x*'φ(x)
, so to verbify it you can say:
(%i14) ev(%, nouns);
2
x
- --
2
x %e
(%o14) - -----------------
sqrt(2) sqrt(%pi)
Looks like the chain rule is applied as expected:
(%i15) diff('φ(x/a), x);
x
x φ(-)
a
(%o15) - ------
2
a
(%i16) ev(%, nouns);
2
x
- ----
2
2 a
x %e
(%o16) - --------------------
2
sqrt(2) sqrt(%pi) a
Upvotes: 0