Skip to main content

Undershoot/Overshoot Method for this differential equation?


I have tried to solve this equation for some weeks and I am not capable. I have read in articles that it is easy with an undershoot/overshoot method, but I don't know how to do it.


$y''+\frac{3}{x}y'-y+\frac{3}{2}y^2-\frac{k}{2}y^3=0$


where $k$ is a constant $0

With the following boundary conditions: $y'(0)=0$ and $y(r)=0$ as $r\rightarrow \infty $


There are problems at $x=0$ but they can be avoided starting $x_i=0.001$.


Thank you very much in advance!!




Answer



For small k,


xs = 10^-4; xm = 12;
s = ParametricNDSolve[{y''[x] + 3 y'[x]/x - y[x] + 3/2 y[x]^2 - k y[x]^3/2 == 0,
y'[xs] == 0, y[xm] == 0}, y, {x, xs, xm}, {k, ys}, Method -> {"Shooting",
"StartingInitialConditions" -> {y[xs] == ys, y'[xs] == 0}}];

f = y[.2, 5.2] /. s;
f[xs]
Plot[f[x], {x, xs, xm}, AxesLabel -> {x, y}, PlotRange -> All]


works well.


(* 5.18512 *)

enter image description here


Addendum - Results at Larger k


Results at larger k can be obtained by extrapolating the Shooting parameter, ys from lower values of k. A simple approach is


start = {{0.01, (y[.01, 5.77] /. s)[xs]}, {0.02, (y[.02, 5.74] /. s)[xs]}};
Do[tem = 2 start[[i - 1, 2]] - start[[i - 2, 2]];
new = {N[i/100], (y[i/100, tem] /. s)[xs]}; AppendTo[start, new], {i, 3, 86}]

ListLinePlot[start, AxesLabel -> {k, "ys"}]

enter image description here


This iterative calculation fails for still larger k, because progressively larger values of xm are needed as k is increased. This is evident from the final result here, at k == 0.86.


f = y @@ Last @ start /. s;
f[xs]
Plot[f[x], {x, xs, xm}, AxesLabel -> {x, y}, PlotRange -> All]

(* 2.58848 *)


enter image description here


To proceed further, a more sophisticated extrapolation process is needed, probably one that extrapolates xm as well as ys. Note, however, that the NDSolve computation rapidly becomes more delicate as xm is increased. It seems likely that a practical limit for this approach will be encountered at k of order 0.90. Still, most of the desired parameter range can be covered in this way.


Second Addendum - Improved Code, Slightly Larger k


At large x, where y[x] is to be very small, the nonlinear terms in the ODE can be ignored, yielding a solution proportional to BesselK[1, x]/x, as can be verified by


FullSimplify[Unevaluated[D[y[x], x, x] + 3 D[y[x], x]/x - y[x]] /. y[x] -> BesselK[1, x]/x]
(* 0 *)

Consequently, an improved boundary condition for large but finite x is


y'[xm] == c y[xm]


where


c = FullSimplify[Unevaluated[D[y[x], x]/y[x]] /. y[x] -> BesselK[1, x]/x]
(* -BesselK[2, xm]/BesselK[1, xm] *)

(and x has been replaced by xm).


To obtain larger values of k, insert the new boundary condition into the ParametricNDSolve expression and increase xm,


xs = 10^-4; xm = 17; c = -BesselK[2, xm]/BesselK[1, xm];
s = ParametricNDSolve[{y''[x] + 3 y'[x]/x - y[x] + 3/2 y[x]^2 - k y[x]^3/2 == 0,
y'[xs] == 0, y'[xm] == c y[xm]}, y, {x, xs, xm}, {k, ys}, Method -> {"Shooting",
"StartingInitialConditions" -> {y[xs] == ys, y'[xs] == 0}}];


and take smaller steps, here 0.005, in the extrapolation loop above. A new version of the loop, using While to check for NDSolve errors, is


start = {{0.005, (y[0.005, 5.7672] /. s)[xs]}, {0.010, (y[0.010, 5.75306] /. s)[xs]}}; 
new = 1; i = 3;
While[new != 0 && start[[i - 1, 1]] <= 1, tem = 2 start[[i - 1]] - start[[i - 2]];
new = Quiet@Check[(y @@ tem /. s)[xs], 0]; If[new != 0,
AppendTo[start, {First@tem, new}]]; i++]
First@Last@start
ListLinePlot[start, AxesLabel -> {k, "ys"}]


(* 0.9 *)

and the second plot, above, is essentially unchanged. Thus, all this has increased the maximum value of k only from 0.88 to 0.9. However, the computation takes only about 17 sec on my computer, so further effort probably can produce slightly larger values of k. To see why it is difficult to obtain solutions for k approaching 9/8, plot the solution for k == 0.9. (See next Addendum for derivation of this maximum value.)


enter image description here


Although this curve looks quite similar to the one above for k = 0.88, the full width at half-maximum (FWHM) is about 11 here and only about 8 there. I speculate that FWHM approaches infinity as k approaches 9/8.


Third Addendum - Larger k Analytical Expression; Duplicate Question


I was somewhat embarrassed to realize an hour ago that I had already solved the equation in this Question almost precisely a year ago as Question 84131, although the present derivaton is more accurate and better automated. The earlier answer noted that derivatives of y[x] nearly vanish at small x for larger k, such as for k == 0.9 in the fourth plot above. Dropping the derivatives and solving the resulting algebraic equation yields,


a = Solve[-ys + 3/2 ys^2 - k ys^3/2 == 0, ys][[3, 1]]
(* ys -> (3 + Sqrt[9 - 8 k])/(2 k) *)


which evaluates to ys == 2.41202 for k == 0.9. This differs from the numerical value of ys,


f = y @@ Last@start /. s; f[xs]
(* 2.41187 *)

by only one part in 10^4, but this is sufficient that ys == 2.41202 is not a good initial guess for computing the k == 0.9 curve, again indicating how delicate the NDSolve computation is for larger k. The analytical estimate (in red), superimposed on the numerical results for ys (in blue), is given by


Show[ListLinePlot[start, AxesLabel -> {k, "ys"}], 
Plot[ys /. a, {k, 0, 9/8}, PlotStyle -> Directive[Dashed, Red]],
PlotRange -> {Automatic, {0, 6}}]

enter image description here



The maximum theoretical value of k is 9/8.


Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...