Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Wrong result for gradient in spherical coordinates

Hello,

I use the following code to calculate the divergence of a scalar field in spherical coordinates:

E.<x,y,z> = EuclideanSpace() CA = E.cartesian_coordinates(); CA BP.<r, θ,="" ϕ&gt;="E.chart(r"r:[0,+oo)" θ:[0,pi]="" ϕ:[0,2*pi]"="" )="" bp_to_ca="BP.transition_map(CA," [r="" *="" sin(θ)="" *="" cos(ϕ),="" r="" *="" sin(θ)="" *="" sin(ϕ),="" r="" *="" cos(θ)])="" g="E.metric()&lt;/p">

E.set_default_chart(BP) E.set_default_frame(BP.frame()) show( g.display() ) show( g.display_comp())

f = E.scalar_field({BP: function('F')(r, θ, ϕ)}, name='f') f.display(BP) f.laplacian().expr(BP).factor()

show(f.gradient().display())

But the result is wrong: grad(f)=∂F∂r∂∂r+∂F∂θr^2∂∂θ+∂F∂ϕr^2sin⁡(θ)^22∂∂ϕ

It must be: grad(f)=∂F∂r∂∂r+∂F∂θr∂∂θ+∂F∂ϕrsin⁡(θ)∂∂ϕ

What am I doing wrong?

Wrong result for gradient in spherical coordinates

Hello,

I use the following code to calculate the divergence of a scalar field in spherical coordinates:

E.<x,y,z> = EuclideanSpace() CA = E.cartesian_coordinates(); CA BP.<r, θ,="" ϕ&gt;="E.chart(r"r:[0,+oo)" θ:[0,pi]="" ϕ:[0,2*pi]"="" )="" bp_to_ca="BP.transition_map(CA," [r="" *="" sin(θ)="" *="" cos(ϕ),="" r="" *="" sin(θ)="" *="" sin(ϕ),="" r="" *="" cos(θ)])="" g="E.metric()&lt;/p">

E.set_default_chart(BP) E.set_default_frame(BP.frame()) show( g.display() ) show( g.display_comp())

f = E.scalar_field({BP: function('F')(r, θ, ϕ)}, name='f') f.display(BP) f.laplacian().expr(BP).factor()

show(f.gradient().display())

But the result is wrong: grad(f)=∂F∂r∂∂r+∂F∂θr^2∂∂θ+∂F∂ϕr^2sin⁡(θ)^22∂∂ϕ

It must be: grad(f)=∂F∂r∂∂r+∂F∂θr∂∂θ+∂F∂ϕrsin⁡(θ)∂∂ϕ

What am I doing wrong?

By the way: how can I define a vector field using BP ?

click to hide/show revision 3
None

Wrong result for gradient in spherical coordinates

Hello,

I use the following code to calculate the divergence of a scalar field in spherical coordinates:

E.<x,y,z> = EuclideanSpace()
CA = E.cartesian_coordinates(); CA
BP.<r, θ,="" ϕ&gt;="E.chart(r"r:[0,+oo)" θ:[0,pi]="" ϕ:[0,2*pi]"="" )="" bp_to_ca="BP.transition_map(CA," [r="" *="" sin(θ)="" *="" cos(ϕ),="" r="" *="" sin(θ)="" *="" sin(ϕ),="" r="" *="" cos(θ)])="" g="E.metric()&lt;/p">
θ, ϕ> = E.chart(r"r:[0,+oo)  θ:[0,pi]  ϕ:[0,2*pi]" )
BP_to_CA = BP.transition_map(CA, [r * sin(θ) * cos(ϕ), r * sin(θ) * sin(ϕ), r * cos(θ)])
g = E.metric()
 

E.set_default_chart(BP) E.set_default_frame(BP.frame()) show( g.display() ) show( g.display_comp())

g.display_comp())

f = E.scalar_field({BP: function('F')(r, θ, ϕ)}, name='f') f.display(BP) f.laplacian().expr(BP).factor()

f.laplacian().expr(BP).factor()

show(f.gradient().display())

show(f.gradient().display())

But the result is wrong: grad(f)=∂F∂r∂∂r+∂F∂θr^2∂∂θ+∂F∂ϕr^2sin⁡(θ)^22∂∂ϕwrong:

grad(f)=∂F∂r∂∂r+∂F∂θr^2∂∂θ+∂F∂ϕr^2sin⁡(θ)^22∂∂ϕ

It must be: grad(f)=∂F∂r∂∂r+∂F∂θr∂∂θ+∂F∂ϕrsin⁡(θ)∂∂ϕbe:

grad(f)=∂F∂r∂∂r+∂F∂θr∂∂θ+∂F∂ϕrsin⁡(θ)∂∂ϕ

What am I doing wrong?

By the way: how can I define a vector field using BP ?

click to hide/show revision 4
retagged

Wrong result for gradient in spherical coordinates

Hello,

I use the following code to calculate the divergence of a scalar field in spherical coordinates:

E.<x,y,z> = EuclideanSpace()
CA = E.cartesian_coordinates(); CA
BP.<r, θ, ϕ> = E.chart(r"r:[0,+oo)  θ:[0,pi]  ϕ:[0,2*pi]" )
BP_to_CA = BP.transition_map(CA, [r * sin(θ) * cos(ϕ), r * sin(θ) * sin(ϕ), r * cos(θ)])
g = E.metric()

E.set_default_chart(BP)
E.set_default_frame(BP.frame())
show( g.display() )
show( g.display_comp())

f = E.scalar_field({BP: function('F')(r, θ, ϕ)}, name='f')
f.display(BP)
f.laplacian().expr(BP).factor()

show(f.gradient().display())

But the result is wrong:

grad(f)=∂F∂r∂∂r+∂F∂θr^2∂∂θ+∂F∂ϕr^2sin⁡(θ)^22∂∂ϕ

It must be:

grad(f)=∂F∂r∂∂r+∂F∂θr∂∂θ+∂F∂ϕrsin⁡(θ)∂∂ϕ

What am I doing wrong?

By the way: how can I define a vector field using BP ?