I have a second order differential equation with two known initial conditions like this:
s = NDSolve[{Y''[x] == -2 δ1/Y[x], Y'[0] == 0, Y[0] == R0i}, Y, {x, 0, 40000}, WorkingPrecision -> 10];
Plot[Evaluate[Y[x] /. s], {x, 0, 40000}, PlotRange -> All]
It worked:
Then I tried the integrate this second order differential equation with two known initial condition,integrate both sides with respect to x and you can get 1/2 (Y'[x])^2 + 2 δ1 Log[Y[x]] = a, then use two known initial conditions Y'[0] == 0, Y[0] == R0i to determine the value of a, then you get:
Y'[x] == Sqrt[4 δ1 Log[R0i/Y[x]]]
But when I try to solve this first order differential equation I got above
s = NDSolve[{Y'[x] == Sqrt[4 δ1 Log[R0i/Y[x]]], Y[0] == R0i}, Y, {x, 0, 40000}];
Plot[Evaluate[Y[x] /. s], {x, 0, 40000}, PlotRange -> All]
I get the different answer1:
And the different answer2 with error message:
NdSolve :: ICRES: NdSolve computation gives the initial value of zero residuals to the differential system, but some components differ from those specified. If they need to be met, it is recommended that explicit initial values be given to all dependent variables.
s = NDSolve[{Y'[x] == Sqrt[4 δ1 Log[R0i/Y[x]]], Y'[0] == 0},
Y, {x, 0, 40000}];
Plot[Evaluate[Y[x] /. s], {x, 0, 40000}, PlotRange -> All]
Does anybody know what the problem is? Maybe it's more of a math problem.
The initial conditions are as follows:
δ = 1.213183119 10^-6;
δ1 = (1 - 1/100) δ;
R0i = 50;



eq = Y''[x] == -2 \[Delta]1/Y[x];. If you solve itDSolve[{eq, Y'[0] == 0, Y[0] == R0i}, Y, x]the solution yieldsY -> Function[{x}, E^-InverseErf[-((2 x Sqrt[\[Delta]1])/(Sqrt[\[Pi]] R0i))]^2 R0i. This is not the expressionY'[x] == Sqrt[4 δ1 Log[R0i/Y[x]]]that you gave in the question. So, how did you obtain the latter expression? – Alexei Boulbitch Mar 24 '21 at 14:45Y[0] == R0iis an obvious singular point of the vector field, i.e., it makesY'[x]equal to zero. Hence the constant solution. -- I believe you have a sign error, too. Start just below the singular point:NDSolve[{Y'[x] == Sqrt[4 \[Delta]1 Log[R0i/Y[x]]], Y[0] == R0i (1 - $MachineEpsilon)}, Y, {x, 0, 40000}]. (I wouldn't useWorkingPrecision -> 10, but if you do, you'll have to use a bigger number than$MachineEpsilonprobably.) – Michael E2 Mar 24 '21 at 15:38Y'[x]and integrate with respect tox. – Michael E2 Mar 24 '21 at 15:40NDSolvecannot numerically distinguish between your desired solution and the singular solution at an initial condition on the singular solution. A typical way to resolve the singularity is to differentiate the DE, which takes you back to your original 2nd-order DE – Michael E2 Mar 24 '21 at 16:13Sqrt[]that is needed to get the desired solution. Darn. Can’t edit comments. If it’s a satisfactory solution, I can make it an answer and fix it. – Michael E2 Mar 24 '21 at 18:311/2 (Y'[x])^2 + 2 δ1 Log[Y[x]] = a, then use two known initial conditionsY'[0] == 0, Y[0] == R0ito determine the value of a, then you getY'[x] == Sqrt[4 δ1 Log[R0i/Y[x]]]– shrocat Mar 25 '21 at 01:20WorkingPrecision -> 50but it still Popup error message:"The differential equation has an accuracy less than WorkingPrecision 10, but it should be bigger than $MachineEpsilon, why the error came up? – shrocat Mar 25 '21 at 01:52MachinePrecision. I would just omit theWorkingPrecisionoption until you better understand how arbitrary precision numbers work.MachinePrecisionis consider to be just slightly less than 16. SettingWorkingPrecisionhigher than that results in a warning. It's only a warning, not an error. Mathematica assumes that if you wanted to do a computation at a certain working precision, the user would supply input at that precision or higher. – Michael E2 Mar 25 '21 at 02:13