Ask Your Question
1

Substitute variable in differential equation

asked 2020-04-08 11:07:00 +0100

Emil Widmann gravatar image

updated 2020-04-11 09:25:47 +0100

I have

m = function('m')(r)
V = function('V')(r)
phi = m(r)/r
V = 4*pi*r^3/3
divG = (diff(phi,r,2)+2/r*diff(phi,r)).full_simplify()

which describes a spherical symmetric source term of a field, nice. Now I want to get this as a function of volume, not of radius and tried:

a=divG.subs(r=V(r))

But it gets me nowhere - It should also substitute the differentials - How to solve this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-04-10 20:05:11 +0100

Juanjo gravatar image

If I am right, you want to transform the differential expression $$\frac{d^2\phi}{dr^2}+\frac{2}{r}\frac{d\phi}{dr},$$ where $$\phi(r)=\frac{m(r)}{r},$$ by changing the independent variable to $V$. The relation between $V$ and $r$ is $$V=\frac{4\pi}{3} r^3.$$ We can think of $m(r)$ as the result of composing two functions: one that yields $V$ in terms of $r$ and then one that yields $m$ in terms of $V$. In other words, an abusing a bit of the notation, $$m(r)=m(V(r)).$$

We can then transform the given differential expression as follows:

var("r,V")
vol = 4*pi*r^3/3
m(V) = function("m")(V)    # m as function of V
M = m(V.subs(V=vol))       # this is m(r)=m(V(r))
phi = M/r
divG = (diff(phi,r,2) + 2/r*diff(phi,r))
divG = divG.subs(vol==V, r^3==3*V/(4*pi)).full_simplify()
show(divG)

In a Jupyter notebook, one gets

$$12 \pi V \frac{\partial^{2}}{(\partial V)^{2}}m\left(V\right) + 8 \pi \frac{\partial}{\partial V}m\left(V\right)$$

that is, in a more proper mathematical notation,

$$4\pi\left( 3V\frac{d^2m}{dV^2}(V)+2\frac{dm}{dV}(V)\right)$$

I hope this has some meaning for you.

edit flag offensive delete link more

Comments

Thanks a lot for showing me. - I got the first term of the solution by hand, but missed the second. The result has a meaning, but what it is I have to figure out, it seems the bracket contains sort of a "density operator".

Emil Widmann gravatar imageEmil Widmann ( 2020-04-11 07:00:22 +0100 )edit

Just 2 more questions: How do I insert latex code here in this forum? How are the symbols D0 and D0,0 defined (result from show(divG), divG in the first version as function from r)?

Emil Widmann gravatar imageEmil Widmann ( 2020-04-11 08:34:58 +0100 )edit

1) This forum uses MathJax to render LaTeX code. You just have to write it as you would do in a TeX file. For example, if you write

This is inline math: $V(r)=4\pi r^3/3$. This is display math:
$$V(r)=\frac{4\pi}{3}r^3.$$

you get, as expected,

This is inline math: $V(r)=4\pi r^3/3$. This is display math: $$V(r)=\frac{4\pi}{3}r^3.$$

Juanjo gravatar imageJuanjo ( 2020-04-11 11:53:24 +0100 )edit

2) If you insert print(divG), you will see that those symbols come from D[0,0](m) and D[0](m). For a multivariate function $f$, D[i,j,k...](f) means the partial derivative of $f$ respect to the $i$-th variable, then the $j$-th variable, then the $k$-th variable and so on. For example, for $f(x,y,z)$, D[2,0,1,2](f) corresponds to $$\frac{\partial^4f}{\partial z\partial x\partial y\partial z},$$ that is, $$\frac{\partial^4f}{\partial x\partial y\partial z^2}$$ if $f\in C^4$. Take into account that, in Python, indices start counting in $0$.

For a univariate function, D[0](f), D[0,0](f), etc. are just their successive derivatives.

Juanjo gravatar imageJuanjo ( 2020-04-11 11:58:50 +0100 )edit

Vielen Dank! I would upvote 2 times more if I could ...

Emil Widmann gravatar imageEmil Widmann ( 2020-04-11 13:28:28 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-04-08 11:07:00 +0100

Seen: 1,162 times

Last updated: Apr 11 '20