Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Coefficients of partial derivatives

In working with the Laplacian of a scalar field, I want to collect the complete coefficient expression of each partial derivative. In 3-space, this can be done "by hand", but in 6-space, automation is essential to avoid error. Consider:

sage: version()
'SageMath version 8.5, Release Date: 2018-12-22'
sage: #Patch to avoid maxima bug
sage: maxima_calculus.eval("domain:real;")
'real'
sage: M = Manifold(3,'R^3',field='real',start_index=1)
sage: c_C.<x,y,z> = M.chart();
sage: c_C.add_restrictions(z>0)
sage: g = M.riemannian_metric('g');
sage: g[1,1],g[2,2],g[3,3] = 1,1,1; 
sage: g.display()
g = dx*dx + dy*dy + dz*dz
sage: c_S.<r,theta,phi> = M.chart(r'r:(0,+oo) theta:(0,pi/2):\theta phi:(0,2*pi):\phi');
sage: ch_C_S = c_C.transition_map(c_S, (sqrt(x^2+y^2+z^2), arccos(z/(sqrt(x^2+y^2+z^2))), arctan2(y,x)))
sage: ch_C_S
Change of coordinates from Chart (R^3, (x, y, z)) to Chart (R^3, (r, theta, phi))
sage: ch_C_S.set_inverse(r*sin(theta)*cos(phi), r*sin(theta)*sin(phi), r*cos(theta))
sage: M.set_default_chart(c_S)    # this saves a little typing later
sage: M.set_default_frame(c_S.frame())
sage: chi = M.scalar_field(function('chi')(r,theta,phi), name='chi', latex_name=r'\chi')
sage: delChi = chi.laplacian(g)
sage: ddChi = delChi.expr()
sage: ddChi.collect_common_factors()
((r^2*diff(chi(r, theta, phi), r, r) + 2*r*diff(chi(r, theta, phi), r) + diff(chi(r, theta, phi), theta, theta))*sin(theta)^2 + cos(theta)*sin(theta)*diff(chi(r, theta, phi), theta) + diff(chi(r, theta, phi), phi, phi))/(r^2*sin(theta)^2)

# We can find the coefficients of scalar variables (sort of):
sage: ddChi.coefficient(r,2); ddChi.coefficient(r,1)
diff(chi(r, theta, phi), r, r)/r^2
2*diff(chi(r, theta, phi), r)/r^2
sage: ddChi.coefficient(sin(theta)^2)    # From which we see that .coefficient() is a shallow operator.
(r^2*diff(chi(r, theta, phi), r, r) + 2*r*diff(chi(r, theta, phi), r) + diff(chi(r, theta, phi), theta, theta))/(r^2*sin(theta)^2)

In the above, we work on the expression for the Laplacian (living in the symbolic ring). But .coefficient() will not work with a partial derivative as argument. Searching through the functions available for delChi (the Laplacian), I see nothing applicable there either. Any suggestions?