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″+3xy′−y+32y2−k2y3=0


where k is a constant $0

With the following boundary conditions: y′(0)=0 and y(r)=0 as r→∞


There are problems at x=0 but they can be avoided starting xi=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

mathematical optimization - Minimizing using indices, error: Part::pkspec1: The expression cannot be used as a part specification

I want to use Minimize where the variables to minimize are indices pointing into an array. Here a MWE that hopefully shows what my problem is. vars = u@# & /@ Range[3]; cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]), cons}, vars, Integers] The error I get: Part::pkspec1: The expression u[1] cannot be used as a part specification. >> Answer Ok, it seems that one can get around Mathematica trying to evaluate vec2[[u[1]]] too early by using the function Indexed[vec2,u[1]] . The working MWE would then look like the following: vars = u@# & /@ Range[3]; cons = Flatten@{ Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; NMinimize[ {Total@((vec1[[#]] - Indexed[vec2, u[#]])^2 & /@ R...

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...

What is and isn't a valid variable specification for Manipulate?

I have an expression whose terms have arguments (representing subscripts), like this: myExpr = A[0] + V[1,T] I would like to put it inside a Manipulate to see its value as I move around the parameters. (The goal is eventually to plot it wrt one of the variables inside.) However, Mathematica complains when I set V[1,T] as a manipulated variable: Manipulate[Evaluate[myExpr], {A[0], 0, 1}, {V[1, T], 0, 1}] (*Manipulate::vsform: Manipulate argument {V[1,T],0,1} does not have the correct form for a variable specification. >> *) As a workaround, if I get rid of the symbol T inside the argument, it works fine: Manipulate[ Evaluate[myExpr /. T -> 15], {A[0], 0, 1}, {V[1, 15], 0, 1}] Why this behavior? Can anyone point me to the documentation that says what counts as a valid variable? And is there a way to get Manpiulate to accept an expression with a symbolic argument as a variable? Investigations I've done so far: I tried using variableQ from this answer , but it says V[1...