Skip to main content

differential equations - Solving nonlinear ODE with boundary conditions


I am trying to solve the below fucntions using a NDsolve, but I can't get the the converges of them at the certain initial variables.I'm using Mathematica 11.3. I appreciate any help.


Z=800;
g= 0.023800000000000000000;
k2= 0.000194519;
R= 1.5472;

ytest0= -13.911917694213733`;
ϵ = $MachineEpsilon ;
y1[ytest_?NumericQ] :=
NDSolve[
{y''[r] + 2 y'[r]/r == k2 Sinh[y[r]] , y[1] == ytest,
y'[ϵ] == 0}, y, {r, ϵ, 1},
Method -> {"StiffnessSwitching", "NonstiffTest" -> False}];
y2[ytest_?NumericQ] :=
NDSolve[
{y''[r] + 2 y'[r]/r == κ2 Sinh[y[r]],

y[1] == ytest, y'[R] == 0}, y, {r, 1, R},
Method -> {"StiffnessSwitching", "NonstiffTest" -> False}];
y1Try[ytest_?NumericQ] := y'[1] /. y1[ytest];
y2Try[ytest_?NumericQ] := y'[1] /. y2[ytest];
f = ytest /. FindRoot[y1Try[ytest] - y2Try[ytest]==-Zg, {ytest, ytest0}]

Answer



The quantity κ2 in the question is undefined. However, the cross-posting identified by Mariusz Iwaniuk in a comment above suggests that k2 actually is meant. With this change, the computation is equivalent to solving the ODE, {y''[r] + 2 y'[r]/r == k2 Sinh[y[r]], y'[R] == 0, y'[ϵ] == 0} with a discontinuity in y'[r] equal to Z g at r == 1. With this modification to the ODE, it can be recast as


Z = 800; g = Rationalize[0.0238, 0];
k2 = Rationalize[ 0.000194519, 0];
ϵ = 10^-4; R = Rationalize[1.5472, 0];

ps = ParametricNDSolveValue[{y''[r] + 2 y'[r]/r == k2 Sinh[y[r]],
y[ϵ] == y0, y'[ϵ] == 0, WhenEvent[r == 1, y'[r] -> y'[r] + Z g]}, {y, y'},
{r, ϵ, R}, {y0}, Method -> "StiffnessSwitching", WorkingPrecision -> 30];
sol = FindRoot[Last[ps[y0]][R], {y0, -11.25, -11.}, Evaluated -> False][[1, 2]]
(* -11.1979 *)

Plot[First[ps[sol]][r], {r, ϵ, R}, AxesLabel -> {r, y}, ImageSize -> Large,
LabelStyle -> {Black, Bold, Medium}]

enter image description here



Plot[Last[ps[sol]][r], {r, ϵ, R}, PlotRange -> All, AxesLabel -> {r, y'}, 
ImageSize -> Large, LabelStyle -> {Black, Bold, Medium}]

enter image description here


The computation takes only seconds.


Addendum


In response to a comment below, the solution for k2 = Rationalize[0.05716690559951900467, 0]; is


sol = Quiet@FindRoot[Last[ps[y0]][R], {y0, -12, 0}, Evaluated -> False][[1, 2]]
(* -5.51467 *)


The corresponding plot of y looks very much like that above but shifted approximately by the shift in y0.


enter image description here


The corresponding plot of y' also looks very much like that above. Note that the FindRoot search range has been expanded in this computation, and Quiet has been prepended to avoid printing the numerous errors that FindRoot encounters before finding the correct answer.


Second Addendum


Varying k2, as requested by the OP in a comment below, is accomplished as follows.


psk = ParametricNDSolveValue[{y''[r] + 2 y'[r]/r == k Sinh[y[r]], 
y[ϵ] == y0, y'[ϵ] == 0, WhenEvent[r == 1, y'[r] -> y'[r] + Z g]}, {y, y'},
{r, ϵ, R}, {y0, k}, Method -> "StiffnessSwitching", WorkingPrecision -> 30];
ytablog = Table[{Exp[k], Quiet@FindRoot[Last[psk[y0, Exp[k]]][R], {y0, -12, 0},
Evaluated -> False][[1, 2]]}, {k, -9, 0, 1/10}];

ListLogLinearPlot[ytablog, PlotRange -> All, Joined -> True, AxesLabel -> {k2, y[0]},
ImageSize -> Large, LabelStyle -> {Black, Bold, Medium}]

enter image description here


A rough fit to this curve is Log[k2] - 2.655. Varying R can be accomplished in a similar manner.


Interestingly, varying R between 5/4 and 2 has minimal effect on the plot just above. Below are plots of y[r] for R = Range[5/4,2,1/4] - {"Blue", "Orange", "Green", "Red"}.


enter image description here


Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.