I am trying to perform numerical integration using the following code:
lagrangian =
1/(6 \[Pi]) Sec[r]^3 Sqrt[4/(1 + Cos[r]^2 + Cos[r]^4) + (x1'[r])^2];
Needs["VariationalMethods`"]
eqofmotion =
Last[EulerEquations[lagrangian, x1[r], r][[1]] //
Numerator] /. {x1'[r] -> 1/y'[x], x1''[r] -> -y''[x]/y'[x]^3} /.
r -> y[x]
eq = eqofmotion y'[x]^3 // Simplify
R[rc_] :=
NDSolveValue[{eq == 0, y[0] == rc, y'[0] == 0}, y, {x, -8, 8}]
Rp[rc_] := D[R[rc][x], x]
xp[rc_] := 1/Rp[rc]
rc[lq_] :=
rc1 /. Quiet@
FindRoot[R[rc1][lq/2] == Pi/2 - 10^-3, {rc1, .0001},
PrecisionGoal -> 4, AccuracyGoal -> 3, Evaluated -> False]
rc[1]
En[lq_?NumericQ] := -2 NIntegrate[(
Sec[\[Chi]]^3 Sqrt[
4/(1 + Cos[\[Chi]]^2 + Cos[\[Chi]]^4) + (xp[\[Chi]])^2])/(
6 \[Pi]), {\[Chi], \[Pi]/2, rc[lq]}]
If I want to get the output of, say, En[1]
, I get errors. How to resolve this issue? Am I missing something here?
R[1]
which is your first very call toNDSolve
and got an error NDSolveValue::ndsz: At x == 0.46930048260328944`, step size is effectively zero; singularity or stiff system suspected. $\endgroup$