EDIT: As pointed out in the comments, VariationalD
gives a variational derivative (which I don't want), not a derivative with respect to a function (i.e. df[x]dloge(x) as a simple example - this is what I thought it did the first time I read the description). Is it even possible in Mathematica to take the derivative of a function with respect to another function? I know you can use the chain rule to rewrite, using the example just above, df[x]dloge(x)=xdf[x]dx. In my case the equivalent would be much more cumbersome and I want to be able to change the function w.r.t. which I'm differentiating. Is it possible to do this in Mathematica?
_
I am using the VariationalMethods`
package, specifically the VariationalD
command. I am trying to take the derivative of one (complicated) function fitted to experimental data with respect to another (complicated) function.
First I wanted to make sure that the command does what I wanted. So I inputted the example given in VariationalD
's "Examples" section:
VariationalD[y[x] Sqrt[y'[x]], y[x], x]
This gives a result of ddy[x](y[x]⋅y′[x]1/2)=2y′[x]2+y[x]y″[x]4y′[x]3/2.
Trying to reproduce this by hand I started with the product rule:
ddy[x](y[x]⋅y′[x]1/2)=y[x]ddy[x]y′[x]1/2+y′[x]1/2ddy[x]y[x]
y′[x]1/2ddy[x]y[x]=y′[x]1/2.
The first term, you use the chain rule on:
y[x]ddy[x]y′[x]1/2=y[x]12y′[x]−1/2ddy[x]y′[x]
Putting all of that together:
ddy[x](y[x]⋅y′[x]1/2)=y′[x]1/2+12y[x]y″[x]y′[x]3/2.
Simplifying:
ddy[x](y[x]⋅y′[x]1/2)=2y′[x]2+y[x]y″[x]2y′[x]3/2,
which is identical to the solution given by VariationalD
except for a factor of 2. So I assumed it was a mistake I made somewhere (and it might be) and tried comparing every step I made when doing it by hand with the corresponding step in VariationalD
. Eventually I discovered one difference in the step
VariationalD[Sqrt[y'[x]], y[x], x]
which gives an answer of y″[x]4y′[x]3/2, a factor of 2 different than when I do it. I'm still not sure where the factor of 2 in the y′[x]1/2ddy[x]y[x] step comes from.
I kept messing around with it and found that
VariationalD[y'[x],y[x],x]=0
which can't be right. For example, if y[x]=x2 and y′[x]=2x,
dy′[x]dy[x]=d(2x)dx2=2(dx2dx)−1=2(2x)−1=1x.
So why is VariationalD
giving a zero answer? It's even weirder because dy′[x]dy[x] comes up when you perform the original differentiation by hand as well. It can't be zero there either or the first term would vanish and the answer would just be y′[x]1/2.
So am I making a stupid mistake in my differentiation? Even if so, why is VariationalD
giving zero for the derivative with respect to a function of its derivative?
I've spent about an hour searching for anything relevant online, and...nothing.
Any help would be appreciated!
EDIT: I've been looking at the description of VariationalD
more closely and now I'm not sure it does what I think it does, i.e.
VariationalD[f[x],g[x],x]
gives df[x]dg[x] as output. Is this correct? Looking at the description it now seems to me that it would give f[x]df[x]dg[x]. But if that's the case then the output for my original expression is still wrong.
Answer
I think VariationalD[y'[x],y[x],x]
indeed equals to zero.
You should not mistake functional derivative with ordinary derivative, where in the former case y′ is usually considered an independent variable to y. so functional dy′/dy=0 is just like an ordinary da/db=0.
The same reason you can't write something like this in calculus of variations
∂J[x,y,y′]∂y=∂x∂y∂J[x,y,y′]∂x,
just like you can't write this in ordinary calculus:
∂f(x,y,z)∂y=∂x∂y∂f(x,y,z)∂x.
Comments
Post a Comment