ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 28 Jan 2020 14:48:21 +0100Symbolic Differential Equation Substitutionhttps://ask.sagemath.org/question/49694/symbolic-differential-equation-substitution/Hi, I have a symbolic partial differential equation like $\nabla^2 P(t,r,\theta,\phi) = 0$. Now I want to substitute the following anzast $P(t,r,\theta,\phi) = e^{-i\omega t} f(r) Y^{m}_{l}(\theta,\phi)$ where the last terms is spherical bessel function. When I wrote,
%display latex
M = Manifold(4, 'M', structure='Lorentzian')
X.<t,r,th,phi> = M.chart(r"t r:(0,+oo) th:(0,pi):\theta phi:(0,2*pi):\phi ")
g = M.metric()
g[0,0] = 1-2/r
g[1,1] = -1/(1-2/r)
g[2,2] = -r^2
g[3,3] = -(r*sin(th))^2
g.display()
w = var('w')
T = e^(-i*w*t)
f = M.scalar_field(function('f')(r), name='f')
l = var('l')
m = var('m')
Y = spherical_harmonic(l,m,th,phi)
P = T*f*Y
eq1 = (dalembertian(P).expr()) == 0
eq1.simplify()
I should get an expression independent of $\theta,\phi$ since the angular part of the equation cancel itself because by definition spherical harmonics satisfies it's own differential equation (see Wolfram-Spherical Harmonics for example). Now when I check manually using
Q = (1/(sin(th))*diff(sin(th)*diff(Y,th),th)+1/((sin(th))^2)*diff(diff(Y,phi),phi)+l*(l+1)*Y)
bool(Q==0)
I got FALSE. To force Sage to use this relation, I tried things like,
eq1.substitute_expression(Q==0).simplify_full()
but they did not work either. The problem roots from the following line,
differentiate(spherical_harmonic(l,m,th,phi),th)
gives expression in terms of higher-order harmonics and Sage is unable to simplify expressions using recursion relations of the spherical harmonics. I also looked at the following integrals
integrate(integrate(spherical_harmonic(l,m,th,phi)*conjugate(spherical_harmonic(l,m,th,phi))*sin(th),th,0,pi),phi,0,2*pi).simplify_full()
but again Sage is unable to evaluate the types of integral unless we plug specific $l,m$. My question is there any way to define spherical harmonics without using a built-in spherical_harmonic() function (like power series) so that Sage would be able to simplify "its differential equation" involving spherical harmonics to automatically zero.Mon, 27 Jan 2020 13:09:05 +0100https://ask.sagemath.org/question/49694/symbolic-differential-equation-substitution/Answer by eric_g for <p>Hi, I have a symbolic partial differential equation like $\nabla^2 P(t,r,\theta,\phi) = 0$. Now I want to substitute the following anzast $P(t,r,\theta,\phi) = e^{-i\omega t} f(r) Y^{m}_{l}(\theta,\phi)$ where the last terms is spherical bessel function. When I wrote,</p>
<pre><code>%display latex
M = Manifold(4, 'M', structure='Lorentzian')
X.<t,r,th,phi> = M.chart(r"t r:(0,+oo) th:(0,pi):\theta phi:(0,2*pi):\phi ")
g = M.metric()
g[0,0] = 1-2/r
g[1,1] = -1/(1-2/r)
g[2,2] = -r^2
g[3,3] = -(r*sin(th))^2
g.display()
w = var('w')
T = e^(-i*w*t)
f = M.scalar_field(function('f')(r), name='f')
l = var('l')
m = var('m')
Y = spherical_harmonic(l,m,th,phi)
P = T*f*Y
eq1 = (dalembertian(P).expr()) == 0
eq1.simplify()
</code></pre>
<p>I should get an expression independent of $\theta,\phi$ since the angular part of the equation cancel itself because by definition spherical harmonics satisfies it's own differential equation (see Wolfram-Spherical Harmonics for example). Now when I check manually using</p>
<pre><code>Q = (1/(sin(th))*diff(sin(th)*diff(Y,th),th)+1/((sin(th))^2)*diff(diff(Y,phi),phi)+l*(l+1)*Y)
bool(Q==0)
</code></pre>
<p>I got FALSE. To force Sage to use this relation, I tried things like,</p>
<pre><code>eq1.substitute_expression(Q==0).simplify_full()
</code></pre>
<p>but they did not work either. The problem roots from the following line,</p>
<pre><code>differentiate(spherical_harmonic(l,m,th,phi),th)
</code></pre>
<p>gives expression in terms of higher-order harmonics and Sage is unable to simplify expressions using recursion relations of the spherical harmonics. I also looked at the following integrals</p>
<pre><code>integrate(integrate(spherical_harmonic(l,m,th,phi)*conjugate(spherical_harmonic(l,m,th,phi))*sin(th),th,0,pi),phi,0,2*pi).simplify_full()
</code></pre>
<p>but again Sage is unable to evaluate the types of integral unless we plug specific $l,m$. My question is there any way to define spherical harmonics without using a built-in spherical_harmonic() function (like power series) so that Sage would be able to simplify "its differential equation" involving spherical harmonics to automatically zero.</p>
https://ask.sagemath.org/question/49694/symbolic-differential-equation-substitution/?answer=49702#post-id-49702Unfortunately, the built-in function `spherical_harmonic()` has many issues, as discussed in this [post](https://groups.google.com/d/msg/sage-support/I_d_meMxRbM/Esxo5UO2BAAJ) (see also ticket [#25034](https://trac.sagemath.org/ticket/25034)).
As suggested in the above [post](https://groups.google.com/d/msg/sage-support/I_d_meMxRbM/Esxo5UO2BAAJ), a workaround is to use the function `spin_weighted_spherical_harmonic()` of the SageMath package [kerrgeodesic_gw](https://pypi.org/project/kerrgeodesic-gw/) with a zero weight, so that you get the standard spherical harmonics. A limitation is that this works only for specific values of $(l, m)$, i.e. you cannot keep $l$ and $m$ as symbolic variables.
See [here](https://share.cocalc.com/share/2b3f8da9-6d53-4261-b5a5-ff27b5450abb/kerrgeodesic_gw/docs/build/html/spin_weighted_spherical_harm.html) for the documentation and examples of use of `spin_weighted_spherical_harmonic()` .
Installing [kerrgeodesic_gw](https://pypi.org/project/kerrgeodesic-gw/) in SageMath is easy: open a terminal and run
sage -pip install kerrgeodesic_gw
NB: on CoCalc, you have to add the option `--user`:
sage -pip install --user kerrgeodesic_gwTue, 28 Jan 2020 14:48:21 +0100https://ask.sagemath.org/question/49694/symbolic-differential-equation-substitution/?answer=49702#post-id-49702