I have a fairly complicated differential expression in terms of a variable r and two unknown functions of r, B[r] and n[r]. I want to do a Taylor expansion of this around r=infinity. I want to do this by defining a new variable x=1/r and changing from r to x within my expression, then expanding around x=0.
Say the expression looks (more or less) like
n[r] (3 r B'[r]^2 - 4 B[r] (2 B'[r] + r B''[r]))
How do I turn this from something in terms of {r, n[r], B[r]} to something in terms of {x, n[x], B[x]}?
I'm not sure how to get Mathematica to work through the chain rule and change the dependent variable in the derivatives, and I also frequently get errors along the lines of "1/r is not a valid variable."
EDIT
I've managed to find at least a solution, although I'd imagine Mathematica has far more elegant ways of doing this. Hopefully if there's a cleaner way to do this someone will post it anyway. It would also be nice to have a more general method for changing variables as my way assumes that only up to second derivatives of B[r] and n[r] appear (since that happens to be true for this problem). Anyway, the solution I found was to do a replacement of the type
n[r] (3 r B'[r]^2 - 4 B[r] (2 B'[r] + r B''[r])) /.
{B'[r] -> B'[x]/D[1/x, x],
B''[r] -> D[(B'[x]/D[1/x, x]), x]/D[1/x, x],
n'[r] -> n'[x]/D[1/x, x],
n''[r] -> D[(n'[x]/D[1/x, x]), x]/D[1/x, x],
B[r] -> B[x],
n[r] -> n[x],
r -> 1/x}
i.e., literally just replacing all of the derivatives w.r.t. r with derivatives w.r.t. x one by one, then replacing B[r] and n[r] with B[x] and n[x], then replacing r itself with 1/x. Not pretty but it does work.
FURTHER EDIT
If you want to do something like this, use Maple. Their PDETools has just the right function which I can't seem to find in Mathematica.
Comments
Post a Comment