# How to rectify the error occurred in solving differential equation?

How to rectify the error occurred in solving differential equation? Such as Indeterminate expression 0. Complex Infinity encountered and also want to use rangakutta method to solve this issue?

g1 = 1;
g = 1;
K1 = .5;
\[Omega]1 = .5; \[Alpha] = \[Pi]/3; T = 1; x0 = 1;
sol1x1xx =
NDSolve[{x1'[t] ==
g1*Sqrt[10 x1[t]] Sin[
x2[t]] (-0.5*Abs[x4[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x3[t]]*x4[t]*Sin[\[Alpha]] +
0.5*Abs[x3[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x4[t]]*x3[t]*Sin[\[Alpha]]) -
K1 Sin[x2[t]]*
Sum[Sin[(1000 + 0.5)*(t - n)]/((2 Pi) Sin[(t - n x0)/2]), {n,
1, 10}],
x2'[t] == (-g1/Sqrt[0.4*x1[t]]) Cos[
x2[t]] (-0.5*Abs[x4[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x3[t]]*x4[t]*Sin[\[Alpha]] +
0.5*Abs[x3[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x4[t]]*x3[t]*Sin[\[Alpha]]) + x1[t],
x3'[t] == ((-I*(x3[
t] (0.5 \[Omega]1 +
0.5 g Sqrt[10 x1[t]] Cos[x2[t]]*Cos[\[Alpha]]) +
0.5 x4[t] g Sqrt[10 x1[t]] Cos[x2[t]]*Sin[\[Alpha]]))/
Sqrt[(Abs[x3[t]]^2 + Abs[x4[t]]^2)]),
x4'[t] == ((-I*(x4[
t] (-0.5 \[Omega]1 -
0.5 g Sqrt[10 x1[t]] Cos[x2[t]]*Cos[\[Alpha]]) +
0.5 x3[t] g Sqrt[10 x1[t]] Cos[x2[t]]*Sin[\[Alpha]]))/
Sqrt[(Abs[x3[t]]^2 + Abs[x4[t]]^2)]), x1[0] == N[\[Pi]/20],
x2[0] == 0, x3[0] == 0, x4[0] == 1}, {x1, x2, x3, x4}, {t, 0,
2 Pi}, Method -> "ExplicitEuler", StartingStepSize -> 0.0002,
MaxSteps -> 10^6];
Plot[Evaluate[Abs[{x1[t], x2[t], x3[t], x4[t]}] /. sol1x1xx[[1]]], {t,
0.1, 2 Pi}, PlotLegends -> {x1, x2, x3, x4}, PlotRange -> All,
PlotLabel -> Row[{"K1 = ", K1, "g1 = ", g1}], AxesLabel -> Automatic,
PlotRange -> All]

• Your code runs without problems for me. I have MMA version 12.1. Did you try with a new kernel? May 18, 2021 at 20:17
• g=0 it is giving an error. May 19, 2021 at 5:02
• Even with g=0 it runs with MMA version 12.1 as you can see below May 19, 2021 at 8:27

Clear["Globals*"]
g1 = 1;
g = 0;
K1 = .5;
\[Omega]1 = .5; \[Alpha] = \[Pi]/3; T = 1; x0 = 1;
sol1x1xx =
NDSolve[{x1'[t] ==
g1*Sqrt[10 x1[t]] Sin[
x2[t]] (-0.5*Abs[x4[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x3[t]]*x4[t]*Sin[\[Alpha]] +
0.5*Abs[x3[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x4[t]]*x3[t]*Sin[\[Alpha]]) -
K1 Sin[x2[t]]*
Sum[Sin[(1000 + 0.5)*(t - n)]/((2 Pi) Sin[(t - n x0)/2]), {n,
1, 10}],
x2'[t] == (-g1/Sqrt[0.4*x1[t]]) Cos[
x2[t]] (-0.5*Abs[x4[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x3[t]]*x4[t]*Sin[\[Alpha]] +
0.5*Abs[x3[t]]^2*Cos[\[Alpha]] +
0.5*Conjugate[x4[t]]*x3[t]*Sin[\[Alpha]]) + x1[t],
x3'[t] == ((-I*(x3[
t] (0.5 \[Omega]1 +
0.5 g Sqrt[10 x1[t]] Cos[x2[t]]*Cos[\[Alpha]]) +
0.5 x4[t] g Sqrt[10 x1[t]] Cos[x2[t]]*Sin[\[Alpha]]))/
Sqrt[(Abs[x3[t]]^2 + Abs[x4[t]]^2)]),
x4'[t] == ((-I*(x4[
t] (-0.5 \[Omega]1 -
0.5 g Sqrt[10 x1[t]] Cos[x2[t]]*Cos[\[Alpha]]) +
0.5 x3[t] g Sqrt[10 x1[t]] Cos[x2[t]]*Sin[\[Alpha]]))/
Sqrt[(Abs[x3[t]]^2 + Abs[x4[t]]^2)]), x1[0] == N[\[Pi]/20],
x2[0] == 0, x3[0] == 0, x4[0] == 1}, {x1, x2, x3, x4}, {t, 0,
2 Pi}, Method -> "ExplicitEuler", StartingStepSize -> 0.0002,
MaxSteps -> 10^6];
Plot[Evaluate[Abs[{x1[t], x2[t], x3[t], x4[t]}] /. sol1x1xx[[1]]], {t,
0.1, 2 Pi}, PlotLegends -> {x1, x2, x3, x4}, PlotRange -> All,
PlotLabel -> Row[{"K1 = ", K1, "g1 = ", g1}], AxesLabel -> Automatic,
PlotRange -> All]


• If we put g1=0 and g=1 then it occurs complex infinity why is it so. May 19, 2021 at 8:01
• I am using mathematica 11 and I am getting an error for g=0 case "Maximum number of 1000000 steps reached at the point t == \ 6.189534468092993". May 19, 2021 at 8:06
• Version: 12.0.0 for Linux x86 (64-bit) also gives the error "Maximum number of 1000000 steps reached at the point t == 6.1613966595956065."
– user49048
May 19, 2021 at 8:34
• The solution for x1[t] diverges near t=1.1. A possible troublemaker is the term Sin[(1000 + 0.5)*(t - n)]/((2 Pi) Sin[(t - n x0)/2])` in the equation for x1. If t==n x0 it diverges. May 19, 2021 at 8:35