Imperfect Bose gas nonlinear Schroedinger type ODE numerical solution

You do not have to repeat the problem to me, I’ve read it. The idea that I am suggesting is that the statement

“I don’t think that domain has necessary to be infinitive but big enough”

leads to an approximation of BC at Infinity - nothing wrong with that. I am just saying potentially there is a mapping of domain that would allow numerical routine to run on the full interval.

NDSolve does not take Infinity as a spec for BC. So one has to trick out, use asymptotic, approximations. Nothing wrong with that - I am just suggesting a potential way to avoid that and rely completely on numerical routine via easy BC obtained from domain mapping.

This mapping could be wrong too because of potential issues that could appear during solution. Maybe other mapping can be tried then. Just an idea.

But can I use NDSolve to solve the equations with u[x=0] = 0 and u[x=1000] = 1 (for example)? How? I’m not an expert in Mathematica. Thanks a lot.

I attacked this problem by making the substitution x = e^{-t}. When subbing for the independent variable, we need to make careful use of the chain rule to express u(x), u'(x), u''(x) in terms of u(t), u'(t), u''(t).

ode = u''[x]+(u'[x]/x)-(u[x]/(x^2))+u[x]-u[x]^3 == 0;
sub = Exp[-t];

newode = ode /. {
    u[x] -> u[t],
	u'[x] -> u'[t]/D[sub, t],
	u''[x] -> (u''[t] - D[sub, {t, 2}] u'[t]/D[sub, t])/D[sub, t]^2,
	x -> sub
}

u[t] - E^(2 t) u[t] - u[t]^3 - E^(2 t) u’[t] + E^(2 t) (u’[t] + u’'[t]) == 0

sol = NDSolveValue[{newode, u[1] == 0, u[0] == 1}, u[t], t] /. t -> Exp[-x];
sol /. x -> 0
sol /. x -> 10^15
Plot[Evaluate[sol], {x, 0, 10}, PlotRange -> All]

Here’s my issue though… If I plug this solution into the original ODE, I don’t get zero, so I think I did something wrong but I can’t figure out where. In fact I am having the same issue with Hans Dolhaine’s solution he posted above (his is sol2 in the plot below).

Maybe someone here can figure out where I went wrong? I feel it’s a simple oversight.

Plot[Evaluate[{
   D[sol, {x, 2}] + (D[sol, x]/x) - (sol/x^2) + sol - sol^3,
   D[sol2, {x, 2}] + (D[sol2, x]/x) - (sol2/x^2) + sol2 - sol2^3
 }], {x, 4, 20}, PlotRange -> All]

Chip,
That’s the same transformation that I used (i used Exp[t] instead of Exp[-t]) see above. Problem is that now your domain in t goes from -infinity to infinity (for t) instead from 0 to infinity (for x). That’s why your answer isn’t right as you solve for t in the interval from 0 to 1.

Ah, ok! When deriving the new domain, I had a typo and used t = e^{-x} instead of x = e^{-t}…

So Chip what I have to chance in your code? Thanks a lot

Vitaly,
Your transform is similar to the one I tried t=x/(1+x) yours: t=Sqrt[x]/(1+Sqrt[x]) . Any reason Sqrt[x}? In any case, NDSolve was unable to solve the transformed equation. I think the reason is that the equation becomes very stiff near the boundaries. Although I’m sure there is a way, I didn’t really spend a lot of time on it.
Mattia mentioned that the equation was solved before, maybe it is worth looking at some literature to see how the problem has been handled in the past.

They used the so called “Chebyshev method”, but I don’t know how it works.

Actually, Kay, I like your transform much better. Could you post your code or attach a notebook or the transformed ODE and NDSolve errors? We could try to figure out a custom method in NDSolve that would handle stiffness.

You can attach PDF papers to your posts and also hyperlink to the papers online. Why don’t you edit your top post and point people to all essential information?

Vitaly,
Ok here it is:

In[201]:= ode1[u_] := D[u, {x, 2}] + D[u, x]/x - u/x^2 + u - u^3;

In[202]:= pdc[ode1[u[x]]]

Out[202]//TraditionalForm= -(u(x)/x^2)+\[PartialD]^2u(x)/\[PartialD]x^2-u(x)^3+u(x)+\[PartialD]u(x)/\[PartialD]x/x

transform equation

In[203]:= teq1 = Expand[ode1[u[x/(1 + x)]]] /. x/(1 + x) -> t /. x -> t/(1 - t)

Out[203]= u[t] - ((1 - t)^2 u[t])/t^2 - u[t]^3 + (
 2 t Derivative[1][u][t])/((1 - t) (1 + t/(1 - t))^3) - (
 3 Derivative[1][u][t])/(1 + t/(1 - t))^2 + ((1 - t) Derivative[1][u][t])/(
 t (1 + t/(1 - t))) + (
 t^2 (u^\[Prime]\[Prime])[t])/((1 - t)^2 (1 + t/(1 - t))^4) - (
 2 t (u^\[Prime]\[Prime])[t])/((1 - t) (1 + t/(1 - t))^3) + (
  u^\[Prime]\[Prime])[t]/(1 + t/(1 - t))^2

In[204]:= teq2 = Simplify[%] t^2

Out[204]= (-1 + 2 t) u[t] - 
 t^2 u[t]^3 + (-1 + 
    t)^3 t ((-1 + 2 t) Derivative[1][u][t] + (-1 + t) t (u^\[Prime]\[Prime])[
      t])

In[205]:= Factor[teq2]

Out[205]= -u[t] + 2 t u[t] - t^2 u[t]^3 + t Derivative[1][u][t] - 
 5 t^2 Derivative[1][u][t] + 9 t^3 Derivative[1][u][t] - 
 7 t^4 Derivative[1][u][t] + 2 t^5 Derivative[1][u][t] + 
 t^2 (u^\[Prime]\[Prime])[t] - 4 t^3 (u^\[Prime]\[Prime])[t] + 
 6 t^4 (u^\[Prime]\[Prime])[t] - 4 t^5 (u^\[Prime]\[Prime])[t] + 
 t^6 (u^\[Prime]\[Prime])[t]

In[206]:= eps = .1;

In[207]:= NDSolve[{teq2 == 0, u[0] == 0, u[1.] == 1.}, u[t], {t, eps, 1.}]

During evaluation of In[207]:= Power::infy: Infinite expression 1/0.^2 encountered. >>

During evaluation of In[207]:= Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered. >>

During evaluation of In[207]:= Power::infy: Infinite expression 1/0.^2 encountered. >>

During evaluation of In[207]:= Power::infy: Infinite expression 1/0.^2 encountered. >>

During evaluation of In[207]:= General::stop: Further output of Power::infy will be suppressed during this calculation. >>

During evaluation of In[207]:= Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered. >>

During evaluation of In[207]:= Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered. >>

During evaluation of In[207]:= General::stop: Further output of Infinity::indet will be suppressed during this calculation. >>

During evaluation of In[207]:= NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. >>

Out[207]= NDSolve[{(-1 + 2 t) u[t] - 
    t^2 u[t]^3 + (-1 + 
       t)^3 t ((-1 + 2 t) Derivative[1][u][t] + (-1 + t) t (
         u^\[Prime]\[Prime])[t]) == 0, u[0] == 0, u[1.] == 1.}, 
 u[t], {t, 0.1, 1.}]

This blows up because of division by zero at the low end. I can fix that by using the low end asymptotic term as t->0 t u’==u:

In[217]:= NDSolve[{teq2 == 0, t u'[eps] == u[eps], u[1.] == 1.}, 
 u[t], {t, eps, 1.}]

During evaluation of In[217]:= NDSolve::ndsz: At t == 0.9999112864801112`, step size is effectively zero; singularity or stiff system suspected. >>

Out[217]= NDSolve[{(-1 + 2 t) u[t] - 
    t^2 u[t]^3 + (-1 + 
       t)^3 t ((-1 + 2 t) Derivative[1][u][t] + (-1 + t) t (
         u^\[Prime]\[Prime])[t]) == 0, 
  t Derivative[1][u][0.1] == u[0.1], u[1.] == 1.}, u[t], {t, 0.1, 1.}]

Now it blows up near t=1 because the differential equation turns into an algebraic equation (u=u^3) via an apparent stiffness at 1 (coefficients of the derivatives start to vanish)

I like this approach: It is sufficient to try various initial conditions for u’[eps] to get the correct boundary condition u[Infinity]=1.
For instance, below there is the code to get a reasonable plot with s=0.2. By the way, it is the plot of the quantum vortex (in a constant background) of the modified Gross-Pitaevskii equation.

s = 0.2 ; 
eps = 10^-4;

eq = u''[x] + (u'[x]/x) - (u[x]/(x^2)) + u[x] - u[x]^3 - s*D[x*D[u[x]^2, x], x]*(u[x]/x) == 0 ; 

sol = u /. NDSolve[{eq, u[eps] == 0, u'[eps] == 1.11}, u, {x, eps, 5}][[1]]

Plot[sol[x], {x, eps, 5}, PlotTheme -> "Detailed"]

Luca,
Nice, you avoid the stiffness issue by using a shooting method! How did you find the initial value of 1.11?

I tried several values for the derivative. Obviously one can improve my choice u’[eps] = 1.11 but I do not think that the improved plot will be very different.

Clearly there is ONLY ONE exact value of u’[eps] to obtain that u[x] to 1 for x \to Infinity, but it is not necessary to find the EXACT value to produce a reasonable plot (for a BSc thesis).

Yes, that sounds good. But what if you integtate to, say, x = 10? At least with my system the solution “explodes”.

And it shows a peculiar behaviour around 1.11. Just have a try with 1.105 and 1.108 and so on…

Mattia is working on it. Notice that with s > 1/2 the equartion becomes nasty (with s = 0 one has the familiar Gross-Pitaevskii equation for a quantized vortex).

It is very easy to show (and everyone knows) that Nonlinear Schrodinger in the simplest case has Tanh kink solution:

f[x_] := Tanh[x/Sqrt[2]];
u''[x] + u[x] - u[x]^3 /. u -> f // FullSimplify

Out[] = 0

That is your equation at asymptotic ‘x → + Infinity’ because

Limit[u'[x]/x - u[x]/x^2,x->0] == 0

And it is clear that solution around zero can be linearized. Now that’s being said Micahel Trott had offered a proper way of finding this solution that you can see below in his reply to tis comment.

High-order series solution of the ODE around x=0 followed by a Pade approximation. difference calculates the difference of the approximation to the right boundary value. It also returns the actual Pade approximation.

difference[\[Alpha]In_Real,\[Xi]_,{prec_, pdO_}] := 
Module[{\[Alpha]=SetPrecision[\[Alpha]In, prec],diff,sol,series,pd,u,x,\[Delta]},  
series=\[Alpha] x -\[Alpha]/8  x^3 ;
Do[diff=u''[x]+u'[x]/x-u[x]/x^2+u[x]-u[x]^3 /.
           u->(Function@@{x,series+C x^M+O[x]^(M+1)});
 series=series  + Together[C x^M /. First[Solve[diff[[3,1]]==0,C]]],{M,5,2pdO+5,2}];
pd=PadeApproximant[series,{x,0,{pdO,pdO}}];
stepData={\[Alpha],\[Delta]=Tanh[10/Sqrt[2]] - pd/. x->10};
{\[Delta], pd /. x -> \[Xi]}
]

Example

difference[0.58318 , x, {20, 20}]

{0.2435578857088556, (0.58318000000000003 x + 0.27407625855333046 x^3 + 0.051256728918896911 x^5 + 0.0048322482238297771 x^7 + 0.00023632082879286407 x^9 + 5.1729410403285544*10^-6 x^11 + 8.2185843137751949*10^-9 x^13 - 1.06931812684189022*10^-9 x^15 - 2.2863733027673254*10^-12 x^17 + 7.6295697669084428*10^-14 x^19)/(1 + 0.59496854925294154 x^2 + 0.142883728435766338 x^4 + 0.0176772849277092897 x^6 + 0.00118228825938525016 x^8 + 0.000039832791262778028 x^10 + 4.5345802881727914*10^-7 x^12 - 5.5226863238549098*10^-9 x^14 - 9.7254616067217217*10^-11 x^16 + 6.0544145050658359*10^-13 x^18 + 3.9887426264821583*10^-15 x^20)}

Find slope at x=0 to any desired precision (by increasing prec and pdO). Say 15 digits.

Monitor[
 fr = FindRoot[
    difference[\[Alpha], x, {100, 200}][[1]], {\[Alpha], 0.5831, 0.5832}, WorkingPrecision -> 60, PrecisionGoal -> 16, 
    Method -> "Brent", Evaluated -> False];,
 stepData]

fr

{\[Alpha] -> 0.583189634418924769412413009673771234659851269345508491782915}

The rational approximate solution.

uSol = difference[\[Alpha] /. fr, x, {100, 200}][[2]];
Plot[Evaluate[uSol], {x, 0, 10}, PlotRange -> All]

Check right boundary condition

(uSol /. x -> 10) - Tanh[10/Sqrt[2]]

-2.6496232607434627305318392508171048229727621206337120044345649125837*10^-27

Check ODE. It is fulfilled to 20 digits everywhere.

odeDiff = u''[x] + u'[x]/x - u[x]/x^2 + u[x] - u[x]^3 /. u -> Function[x, Evaluate[uSol]];

Quiet[ Plot[Log10[Abs[odeDiff]], {x, 0, 10}, WorkingPrecision -> 200, 
  GridLines -> {None, {-20}}, PlotRange -> {Full, {All, 0}}], Plot::precw]

Notebook is attached.