1

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
  • 2
    You'd need to specify bounds for the independent variables, like {r, 0, 1}, {ph, 0, \[Pi]}, {th, 0, \[Pi]} – user21 Mar 31 '21 at 08:49
  • 2
    Also, you need periodic b.c. One example: https://mathematica.stackexchange.com/a/239239/1871 – xzczd Mar 31 '21 at 08:55
  • @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. – Daniel Huber Mar 31 '21 at 10:46
  • It should be {ph, 0, Pi}, {th, -Pi, Pi}. Please check the definition of "Spherical" coordinates in Mathematica carefully. – xzczd Mar 31 '21 at 11:06
  • @xzczd Thanks a lot. I corrected this, but now I get a constant instead of 1/r. It is sort of embarrassing, but I want to understand how to use the Laplacian operator in MMA. – Daniel Huber Mar 31 '21 at 13:28
  • 2
    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. – xzczd Mar 31 '21 at 13:43
  • @xzczd Thanks again, without some hints, I would not get anywhere. Now it starts to resemble 1/r. But it is astonishing that DSolve can not deal with this simplest of a test example. – Daniel Huber Mar 31 '21 at 16:46
  • If you only care about the spherically symmetric case, directly solve the ODE will be the easiest: Limit[DSolveValue[{Laplacian[f[r], {r, th, ph}, "Spherical"] == 0, f[1] == 1, f[inf] == 0}, f[r], r], inf -> Infinity] – xzczd Apr 01 '21 at 03:16
  • @ xzczd I want to learn how to use the Laplacian operator. The spherically symmetric case was only a simple test example. – Daniel Huber Apr 01 '21 at 08:11

0 Answers0