I would like to solve the following boundary value problem for $y(x)$ for a fixed value of $k$ between $0 < k <1$:
$$y'' + \frac{3}{x} y' - y + \frac{3}{2}y^2 - \frac{k}{2}y^3=0 \\ y'(0) = 0,\qquad y(\infty)\rightarrow0$$
To make this work, I truncate the domain of the problem to $x_0 < x < x_\text{Max}$ to avoid the singularity at $x=0$ and so that the second boundary condition is brought to a finite $y(x_\text{Max})=0$. I will be working with $x_0 = 0.01$ and $x_\text{Max} = 10.$
I want to write a fast Mathematica program to solve this by using undershoot/overshoot on the related initial-value problem $y(x_0) = y_0$ to achieve the second boundary condition $y(x_\text{Max}) = 0$.
So far, I wrote a nice little code that solves the initial-value problem for a given $k$ and $y_0$:
sol = With[{x0 = .01, xMax = 10},
ParametricNDSolveValue[
{y''[x] + 3/x y'[x] - y[x] + 3/2 y[x]^2 - k/2 y[x]^3 == 0 (*diff.eq.*),
y[x0] == y0 + 1/8 x0^2 (y0 - 3/2 y0^2 + k/2 y0^3) (*init.cond.1*),
y'[x0] == 1/4 x0 (y0 - 3/2 y0^2 + k/2 y0^3) (*init.cond.2*),
WhenEvent[y[x] == 0, {Print["Overshot"], "StopIntegration"}],
WhenEvent[y'[x] == 0, {Print["Undershot"], "StopIntegration"}]
},
y, {x, x0, xMax}, {k, y0}]]
The solutions are obtained by calling sol[k,y0][x]
and can be plotted by giving numbers for k
and y0
.
Example: Take $k=0.4$
Then, $y_0 = 6.0$ (blue) leads to an "overshoot", $y_0 = 3.0$ (red) leads to an "undershoot", and $y_0 = 4.51114$ (black) is the "sweetspot" which gives the solution to the boundary value problem.
Question: What is the best way (in terms of performance) to automate getting the solution to the boundary value problem in Mathematica?
I definitely know that the correct $y_0$ lies somewhere between $\frac{3-\sqrt{9-8k}}{2k} < y_0 < \frac{3+\sqrt{9-8k}}{2k}$.
Appendix: the following code generates the graphic above.
plot1 = Plot[sol[0.4, 6][x], {x, .01, sol[0.4, 6]["Domain"][[1, 2]]}, PlotStyle -> Blue];
plot2 = Plot[sol[0.4, 3][x], {x, .01, sol[0.4, 3]["Domain"][[1, 2]]}, PlotStyle -> Red];
plot3 = Plot[sol[0.4, 4.51114][x], {x, .01, sol[0.4, 4.51114]["Domain"][[1, 2]]}, PlotStyle -> {Black, Thick}];
Show[plot1, plot2, plot3, PlotRange -> {{0, 10}, {-1, 6}}]
y[x0]
andy'[x0]
as a polynomial in your code? Thanks! $\endgroup$x
behavior of the solution atx=x0
. I can't start integration right atx=0
because that is a singular point. $\endgroup$