1
$\begingroup$

I am trying to solve a simple test example using Laplacian. But I step from one problem to the next.

First I did not realized, that MMA uses spherical coordinates in the order: r,theta,phi and not, as I was accustomed to: r,phi,theta. Now as this is corrected, I get a constant instead of the expected function:

Consider a unit sphere having an electrostatic potential of 1. It is well know that the potential in the 3D charge free outside this sphere is 1/r.

Using Laplacian in spherical coordinates, this can be written by:

Clear[sol, f, r, ph, th]
rmax = 10;
sol[r_, th_, ph_] = 
 f[r, th, ph] /. 
  NDSolve[{Laplacian[f[r, th, ph], {r, th, ph}, "Spherical"] == 0, 
     f[1, th, ph] == 1}, 
    f, {r, 1, rmax}, {th, 0, Pi}, {ph, -Pi, Pi}][[1]]
Plot[{sol[r, 0, 0], 1/r}, {r, 1, rmax}, PlotRange -> All]

enter image description here

Instead of 1/r I get a constant of 1, independent of rmax.

Further, if I give a periodic boundary condition., MMA complains about an "overdetermined system". And MMA can not do the calculation with increased working precision.

DSolve does not even give a result, it simply gives the equation back.

Update:

As xzczd remarked, if no boundary condition at infinity is given, MMA assumes Neumann conditions, that is it sets the derivatives to zero, what then gives a constant for the solution.

Therefore I choose rmax =100 (large enough) and specify `` f[rmax, th, ph] == 0`:

Clear[sol, f, r, ph, th]
rmax = 100;
sol[r_, th_, ph_] = 
 f[r, th, ph] /. 
  NDSolve[{Laplacian[f[r, th, ph], {r, th, ph}, "Spherical"] == 0, 
     f[1, th, ph] == 1, f[rmax, th, ph] == 0}, 
    f, {r, 1, rmax}, {th, 0, Pi}, {ph, -Pi, Pi}][[1]]
Plot[{sol[r, 0, 0], 1/r}, {r, 1, 10}, PlotRange -> All]

enter image description here

Now we at least get something similar to 1/r.

Uff.., earning is hard, but it is better to look like a fool for a short time than being one for the rest of ones life.

$\endgroup$
9
  • 2
    $\begingroup$ You'd need to specify bounds for the independent variables, like {r, 0, 1}, {ph, 0, \[Pi]}, {th, 0, \[Pi]} $\endgroup$
    – user21
    Commented Mar 31, 2021 at 8:49
  • 2
    $\begingroup$ Also, you need periodic b.c. One example: mathematica.stackexchange.com/a/239239/1871 $\endgroup$
    – xzczd
    Commented Mar 31, 2021 at 8:55
  • $\begingroup$ @user21 Thanks', I knew that I made a stupid error. However, things get even worse when MMA does some evaluation. I changed my question accordingly. $\endgroup$ Commented Mar 31, 2021 at 10:46
  • $\begingroup$ It should be {ph, 0, Pi}, {th, -Pi, Pi}. Please check the definition of "Spherical" coordinates in Mathematica carefully. $\endgroup$
    – xzczd
    Commented Mar 31, 2021 at 11:06
  • 2
    $\begingroup$ The constant solution is expected, because you haven't set b.c. at rmax to approximate b.c. at infinity, so FiniteElement method by default uses zero Neumann value as the b.c., which leads to the solution $f=1$. A possible b.c. at rmax is DirichletCondition[f[r, th, ph] == 0, r == rmax && -Pi < ph < Pi], you need to make rmax large enough, though. $\endgroup$
    – xzczd
    Commented Mar 31, 2021 at 13:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.