I have the following code, in which I try to solve a system of three coupled differential equation numerically:
The code:
(*Parameters*)
(*precision:20,50,\[Infinity]*)
pr := \[Infinity]
prr := pr - 5
cut := 1/1000000000
\[Epsilon] := SetPrecision[1/10, pr]
L := SetPrecision[1, pr]
d := SetPrecision[1/100, pr]
\[Phi] := SetPrecision[\[Pi]/8, pr]
\[Chi]m := SetPrecision[0, pr]
\[Chi]p := SetPrecision[0, pr]
\[Alpha]p := SetPrecision[1, pr]
N5 := SetPrecision[2, pr]
N3 := SetPrecision[20, pr]
\[CapitalDelta]N3 := SetPrecision[2, pr]
gYM := SetPrecision[10, pr]
\[Delta] =
SetPrecision[
1/2 Log[1/(
gYM^2 N5^2 (2 N3 - \[CapitalDelta]N3)) (2 gYM^2 N3 N5^2 +
4 \[Pi]^2 \[CapitalDelta]N3^2 +
Sqrt[(2 gYM^2 N3 N5^2 + 4 \[Pi]^2 \[CapitalDelta]N3^2)^2 -
gYM^4 N5^4 (4 N3^2 - \[CapitalDelta]N3^2)])], pr];
\[Alpha] =
SetPrecision[-(N5/4) Cosh[\[Delta]] +
Sqrt[(\[Pi]^2 N3)/gYM^2 + N5^2/16 Cosh[\[Delta]]^2], pr];
\[Alpha]h = SetPrecision[(gYM^2 \[Alpha])/(4 \[Pi]), pr];
(*harmonic functions and definitions*)
h1 = \[Alpha]p (-I \[Alpha] Sinh[v] -
N5/4 Log[
Tanh[(I \[Pi])/4 - (v - \[Delta])/
2]]) + \[Alpha]p (I \[Alpha] Sinh[vb] -
N5/4 Log[Tanh[-((I \[Pi])/4) - (vb - \[Delta])/2]]);
h2 = \[Alpha]p \[Alpha]h (Cosh[v] + Cosh[vb]);
w = D[D[h1 h2, vb], v];
F1 = 2 h1 h2 D[h1, v] D[h1, vb] - h1^2 w;
F2 = 2 h1 h2 D[h2, v] D[h2, vb] - h2^2 w;
f42s = N[2 ((F1 F2)/w^2)^(1/4), prr];
\[Rho]2s = N[2 h2^2 ((F1 w^2)/F2^3)^(1/4), prr];
subv = {v -> x[x2] + I y[x2], vb -> x[x2] - I y[x2]};
(*Coeff functions inside the eoms*)
(*THESE FUNCTIONS ARE INSIDE THE DIFFERENTIAL EQUATIONS BELOW*)
(*these functions will be evaluated at the initial values given \
below, BUT they give undefined values or non-significant digits \
depending on the precision*)
Logfx = SetPrecision[D[Log[f42s /. subv], x[x2]], prr];
Logfy = SetPrecision[D[Log[f42s /. subv], y[x2]], prr];
Log\[Rho]x = SetPrecision[D[Log[\[Rho]2s /. subv], x[x2]], prr];
Log\[Rho]y = SetPrecision[D[Log[\[Rho]2s /. subv], y[x2]], prr];
f\[Rho]x =
SetPrecision[D[f42s /. subv, x[x2]]/(\[Rho]2s /. subv), prr];
f\[Rho]y =
SetPrecision[D[f42s /. subv, y[x2]]/(\[Rho]2s /. subv), prr];
(*Lagrangian and equations of motion*)
(*f42 is Subscript[f, 4](x,y)^2 and \[Rho]2 is \[Rho](x,y)^2*)
(*Subscript[f, 4](x,y) and \[Rho](x,y) are given*)
(*SUBSTITUTIONS*)
subeq = { f42[x[x2], y[x2]] -> f42,
\!\(\*SuperscriptBox[\(f42\),
TagBox[
RowBox[{"(",
RowBox[{"0", ",", "1"}], ")"}],
Derivative],
MultilineFunction->None]\)[x[x2], y[x2]] -> f42y,
\!\(\*SuperscriptBox[\(f42\),
TagBox[
RowBox[{"(",
RowBox[{"1", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[x[x2], y[x2]] ->
f42x, \[Rho]2[x[x2], y[x2]] -> \[Rho]2,
\!\(\*SuperscriptBox[\(\[Rho]2\),
TagBox[
RowBox[{"(",
RowBox[{"1", ",", "0"}], ")"}],
Derivative],
MultilineFunction->None]\)[x[x2], y[x2]] -> \[Rho]2x,
\!\(\*SuperscriptBox[\(\[Rho]2\),
TagBox[
RowBox[{"(",
RowBox[{"0", ",", "1"}], ")"}],
Derivative],
MultilineFunction->None]\)[x[x2], y[x2]] -> \[Rho]2y};
(*I dont know if the last line will be clear as code, so I added a \
copy of it below*)
(*subeq={ f42[x[x2],y[x2]]\[Rule]f42,D[ \
f42[x[x2],y[x2]],y[x2]]\[Rule]f42y,D[ \
f42[x[x2],y[x2]],x[x2]]\[Rule]f42x,\[Rho]2[x[x2],y[x2]]\[Rule]\ [Rho]2,\
D[\[Rho]2[x[x2],y[x2]],x[x2]]\[Rule]\[Rho]2x,D[\[Rho]2[x[x2],y[x2]],y[\
x2]]\[Rule]\[Rho]2y};*)
subu = {f42x -> A f42, f42y -> B f42};
subxy = {f42x -> F \[Rho]2,
f42y -> G \[Rho]2, \[Rho]2x -> H \[Rho]2, \[Rho]2y -> J \[Rho]2};
subwarp2 = {A -> Logfx, B -> Logfy, H -> Log\[Rho]x, J -> Log\[Rho]y,
F -> f\[Rho]x, G -> f\[Rho]y};
(*Lagrangian*)
Lag = f42[x[x2], y[x2]] (u'[x2]^2/u[x2]^2 + 2/u[x2]^2) + \[Rho]2[
x[x2], y[x2]] (x'[x2]^2 + y'[x2]^2);
(*SET OF EQUATIONS OF MOTION where A,B,F,G,H and J are defined above*)
(*eom for u(x2)*)
equ = (u[x2]^2)/(2 f42) (D[Lag, u[x2]] - D[D[Lag, u'[x2]], x2]) /.
subeq /. subu // Expand;
(*eom for x(x2)*)
eqx = 1/(2 \[Rho]2) (D[Lag, x[x2]] - D[D[Lag, x'[x2]], x2]) /.
subeq /. subxy // Expand;
(*eom for y(x2)*)
eqy = 1/(2 \[Rho]2) (D[Lag, y[x2]] - D[D[Lag, y'[x2]], x2]) /.
subeq /. subxy // Expand;
(*collecting the equations*)
equu = (equ + u''[x2]) /. subwarp2;
eqxx = (eqx + x''[x2]) /. subwarp2;
eqyy = (eqy + y''[x2]) /. subwarp2;
pdes = {u''[x2] == equu, x''[x2] == eqxx, y''[x2] == eqyy};
(*Boundary conditions*)
(*initial and final values of x2*)
x20 = SetPrecision[-d Cos[\[Phi]], prr];
x21 = SetPrecision[d Cos[\[Phi]], prr];
(*initial values of u,x and y*)
u0 = SetPrecision[\[Epsilon] Sqrt[
1 + ((L - d Sin[\[Phi]])/\[Epsilon])^2], prr];
x0 = SetPrecision[ArcSinh[(L - d Sin[\[Phi]])/\[Epsilon]], prr];
y0 = SetPrecision[\[Pi]/2 - \[Chi]m, prr];
(*Final values*)
u1 = SetPrecision[\[Epsilon] Sqrt[
1 + ((L + d Sin[\[Phi]])/\[Epsilon])^2], prr];
x1 = SetPrecision[ArcSinh[(L + d Sin[\[Phi]])/\[Epsilon]], prr];
y1 = SetPrecision[\[Pi]/2 - \[Chi]p, prr];
(*required condition*)
L - d Sin[\[Phi]] > 0
(*boundary conditions*)
bcs = SetPrecision[{x[x20] == x0, u[x20] == u0, y[x20] == y0,
x[x21] == x1, u[x21] == u1, y[x21] == y1}, prr];
(*slight deformation of the initial conditions*)
cor := SetPrecision[1/1000000, prr]
bcs2 = SetPrecision[{x[x20] == x0 + cor, u[x20] == u0 + cor,
y[x20] == y0 + cor, x[x21] == x1 + cor, u[x21] == u1 + cor,
y[x21] == y1 + cor}, prr];
(*Solving eoms*)
(*NDSolve[Flatten[{pdes,bcs}],{u[x2],x[x2],y[x2]},{x2,x20,x21},Method\
\[Rule]{"ExplicitRungeKutta","DifferenceOrder"\[Rule]2},\
WorkingPrecision\[Rule]70][[1]];*)
subin = SetPrecision[{u[x20] -> u0, x[x20] -> x0, y[x20] -> y0}, prr];
subin2 = SetPrecision[{u[x20] -> u0 + cor, x[x20] -> x0 + cor,
y[x20] -> y0 + cor}, prr];
(*Evaluating the eoms at the initial value of x20*)
bcsin = {x[x20] == x0, u[x20] == u0, y[x20] == y0};
bcsin2 = {x[x20] == x0 + cor, u[x20] == u0 + cor, y[x20] == y0 + cor};
(*EVALUATION AT THE ORIGINAL INITIAL VALUES*)
NDSolve[Flatten[{pdes, bcs}], {u[x2], x[x2], y[x2]}, {x2, x20, x21},
Method -> {"Shooting", "StartingInitialConditions" -> bcsin},
WorkingPrecision -> MachinePrecision][[1]];
NDSolve::ndsz: At x2 == -0.0092388, step size is effectively zero; singularity or stiff system suspected. >>
(*EVALUATION AT THE "DEFORMED INITIAL VALUES*)
NDSolve[Flatten[{pdes, bcs2}], {u[x2], x[x2], y[x2]}, {x2, x20, x21},
Method -> {"Shooting", "StartingInitialConditions" -> bcsin2},
WorkingPrecision -> MachinePrecision][[1]];
NDSolve::ndsz: At x2 == -0.0092388, step size is effectively zero; singularity or stiff system suspected. >>
Now the problem. Initially, I set the variable to some numerical values, and there is a chain of definitions involving them, ok. Since some of them are trigonometric functions, square roots, etc; I set infinite precision (which displays numbers inside these functions, e.g Sin[pi/2]
instead Sin[3.14.../2]
), so coefficient functions are finally evaluated in those parameters and depend only on functions and numbers (with infinite precision, i.e non-functional expressions).
I know that Mathematica deal BVP with Shooting method. I also know that NDSolve
needs numerical values inside the equations, that is why I set WorkingPrecision
to MachinePrecision
. The problema appear when I run the code and get
NDSolve::ndsz: "At x0 == (number), step size is effectively zero; singularity or stiff system suspected."
So the problems looks to be at the beginning. I evaluated the coefficient functions inside the PDEs and saw that indeed x=x0
gives something like
"Infinite expression 1/(0.*10^-37+0.*10^-37\I) encountered."
Maybe there are analytic zeroes inside the coefficient functions, I thought, so I applied Chop
to set zero small numbers. When I evaluate the coefficient functions I get
no significant digits to display
And something like 0.x10^-20
or 0.x10^50
. These "numbers" spoil the evaluation and the method, I think... producing something like 1/0
in the middle steps.
Any suggestion? I hope you understand the problem.
**Parameters**
etc. by(*Parameters*)
. $\endgroup$x2 == 0
? Etc. $\endgroup$