I want to solve a differential equation of second order with complex initial conditions. Despite I have wrote all the code with detail, I am still facing some problems I might want to review here. The code is as follows:
ode1 = x''[t] + 3 x'[t] Sqrt[(x'[t])^2/6 + (1 - Exp[-x[t] Sqrt[2/3]])^2/4] + Sqrt[3/2] Exp[-x[t] Sqrt[2/3]] (1 - Exp[-x[t] Sqrt[2/3]]) == 0
ode1IC = {x'[0] == -0.008226306418212731, x[0] == 5.630991866033891};
solX = NDSolve[{ode1, ode1IC}, x, {t, 0, 500}][[1, 1]]
ode2 = a'[t]/a[t] == Sqrt[(x'[t])^2/6 + (1 - Exp[-x[t] Sqrt[2/3]])^2/4];
ode2 = ode2 /. solX;
ode2IC = a[0] == 1;
sola = NDSolve[{ode2, ode2IC}, a, {t, 0, 500}][[1, 1]]
ode3 = \[Tau]'[t] == 1/a[t];
ode3 = ode3 /. sola;
ode3IC = \[Tau][149.4517772937791] == 0;
solTao = NDSolve[{ode3, ode3IC}, \[Tau], {t, 0, 500}][[1, 1]]
f = ((7.41193*10^6)^2 - ((3/2 + 1/2*((Sqrt[3/2] Exp[-x[t] Sqrt[2/3]] (1 - Exp[-x[t] Sqrt[2/3]]))/(3/4 (1 - Exp[-x[t] Sqrt[2/3]])^2))^2 + 1/2 ((Exp[-Sqrt[8/3] x[t]] (1 - Exp[Sqrt[2/3] x[t]] (1 - Exp[-Sqrt[2/3] x[t]]))/(3/4 (1 - Exp[-x[t] Sqrt[2/3]])^2))))^2 - 1/4)/(\[Tau][t])^2) /. {solX,solTao};
ode4 = u''[t] + f*u[t] == 0;
ode4 = SetAccuracy[(Solve[ode4, u''[t]] /. Rule -> Equal)[[1, 1]] //
Simplify, Infinity];
ode4 = ode4 /. {solTao, solX};
ic={u[0]==0.000259728 E^(I (-0.0249668)),u'[0]==1925.09 E^(I (-1.59576))};
ic=SetAccuracy[ic,Infinity];
sol = DSolveValue[{ode4, ic}, u[t], t];
I am interested in Plotting the solution of ode4. When running the Plot for the solution, it shows.
Plot[Abs@sol,{t,0,100}]
DSolveValue::dsvar: The variable specification is not valid.
General::stop: Further output of DSolveValue::dsvar will be suppressed during this calculation.
How do I solve it?
Update:
This is what happens when running the sol code.
NDSolve[{x''[t] + 3 x'[t] Sqrt[(x'[t])^2/6 + (1 - Exp[-x[t] Sqrt[2/3]])^2/4] + Sqrt[3/2] Exp[-x[t] Sqrt[2/3]] (1 - Exp[-x[t] Sqrt[2/3]]) == 0, a'[t]/a[t] == Sqrt[(x'[t])^2/6 + (1 - Exp[-x[t] Sqrt[2/3]])^2/4], \[Tau]'[t] == 1/a[t], u''[t] + ((7.41193*10^6)^2 - ((3/2 + 1/2*((Sqrt[3/2] Exp[-x[t] Sqrt[2/3]] (1 - Exp[-x[t] Sqrt[2/3]]))/(3/4 (1 - Exp[-x[t] Sqrt[2/3]])^2))^2 + 1/2 ((Exp[-Sqrt[8/3] x[t]] (1 - Exp[Sqrt[2/3] x[t]] (1 - Exp[-Sqrt[2/3] x[t]]))/(3/4 (1 - Exp[-x[t] Sqrt[2/3]])^2))))^2 - 1/4)/(\[Tau][t])^2)*u[t] == 0, x'[0] == -0.008226306418212731, x[0] == 5.630991866033891, a[0] == 1, \[Tau][149.4517772937791] == 0, u[0] == 0.000259728 E^(I (-0.0249668)), u'[0] == 1925.09 E^(I (-1.59576))}, {x, \[Tau], a, u}, {t, 0, 100}]
Power::infy: Infinite expression 1/0.^2 encountered.
Infinity::indet: Indeterminate expression 1.5 +ComplexInfinity+ComplexInfinity encountered.
General::stop: Further output of Power::infy will be suppressed during this calculation.
Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered.
General::stop: Further output of Infinity::indet will be suppressed during this calculation.
NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`.
Both methods seem to have problems. Which is the best way to solve them?
Second update:
I figured out that I can solve the system with NDSolve, the trouble is that it takes so much time to solve. I need to make it efficient, but even though with a million steps, I see that it has only been solved from 0 to 0.08, when I want to solve it for the first 100 in $t$.
solode = NDSolve[{u''[t] + u[t]*(k55^2 - f) == 0, u[0] == 0.000259728 E^(I (-0.0249668)), u'[0] == 1925.09 E^(I (-1.59576))}, u, {t, 0, 20}, WorkingPrecision -> 30, MaxSteps -> 1000000]
What is difficult to understand for me is that the first time I ran this code, it achieved to cover a solution from $t=0$ to $t=20$, and now it doesn't go further more from zero. Is there any way to solve this efficiency problem?
Observe here that $k_{55}$ is a fixed constant, while $f$ is a function, which is
\[Nu] = 3/2 + eps1 + 1/2*eps2
f = (\[Nu]^2 - 1/4)/(\[Tau]^2)
The terms that form $f$ are also functions with respect to $t$, all of them well defined and already solved by another NDSolve previously in the code. $u(t)$ is the function that I need a solution for; however, since it oscillates too much in extended times, it can be difficult without precision. Next image is the
ReImPlot[u[t]/.solode,{t,0,20}]
ode1
in your code that you want to solve? If so, its IC's are not complex. This is confusing. Also you have typo in pasting your code forf
it has--
there near the end which gives syntax error. $\endgroup$DSolveValue
) a numerical solution. I thought that usually would not work. DoesDSolveValue
actually give you a solution? $\endgroup$f
is of order 5 10^13 for smallt
, sou
oscillates very rapidly there, which is why the numerical calculation ofu
is so slow. Certainly, this is inconsistent with the plot in the question. $\endgroup$u[t]
would make it easier for Mathematica to solve the system? $\endgroup$