There are mixture of exact numbers and real numbers with several digits like 0.05886
in eqnlist
, therefore we can't use WorkingPrecision
higher then $MachinePrecision
as an option in FindRoot
. To solve this problem we can use NMinimize
. First, remove all ==
from eqnlist
with
eq = Table[
eqnlist[[i]][[1]] - eqnlist[[i]][[2]], {i, Length[eqnlist]}];
and use it as follows
sol =
NMinimize[eq . Conjugate[eq], {TT[t], N2[t], SS'[t], PP'[t], z'[t]},
MaxIterations -> 1000, PrecisionGoal -> 5, AccuracyGoal -> 5]
Out[]= {1.356*10^-6, {TT[t] -> 0.841065, N2[t] -> 24.7031,
Derivative[1][SS][t] -> -0.0946177,
Derivative[1][PP][t] -> -0.015582,
Derivative[1][z][t] -> -0.000194137}}
Second, use sol
with FindRoot
in the form
sol1 =
FindRoot[Table[eq[[i]] Conjugate[eq[[i]]] == 0, {i, Length[eq]}],
Table[{var[[i]], var[[i]] /. sol[[2]]}, {i, Length[var]}],
MaxIterations -> 1000, PrecisionGoal -> 6, AccuracyGoal -> 6]
Out[]= {TT[t] -> 0.841069, N2[t] -> 24.5294,
Derivative[1][SS][t] -> -0.00237493,
Derivative[1][PP][t] -> -0.000395797,
Derivative[1][z][t] -> -4.92941*10^-6}
Let check that eq
been solved with maximal error of $2.37\times 10^{-5}$
Table[eq [[i]], {i, 5}] /. sol1
Out[]= {-4.92942*10^-6, -0.0000237491, -0.000010477, \
-4.13951*10^-9, -1.76118*10^-6}
Hence the value z'[t]
needs to be recalculated. We can plot eq
as function of z'[t]
as
Plot[Log[eq . Conjugate[eq] /. Drop[sol1, -1]], {z'[t], -10^-4, 0}]
The minimal value of eq . Conjugate[eq]
is about $10^{-21}$ it is why we can't solve this problem with $MachinePrecision
using FindRoot
. Now we can try
sol2=NMinimize[{Log[eq . Conjugate[eq] /. Drop[sol1, -1]],
z'[t] < 0}, z'[t]]
Out[]= {-21.0926, {Derivative[1][z][t] -> -2.95916*10^-6}}
Let check how we improve solution
Table[eq [[i]], {i, 5}] /. Join[Drop[sol1, -1], sol2[[2]]]
Out[]= {-2.95917*10^-6, -0.0000237491, -0.0000104769, \
-4.13951*10^-9, -2.93993*10^-6}
Compare to that find above with sol1
we improve first and last equations. We can recommend turn all numbers to rational and use option WorkingPrecision -> 40
with sol1
as starting point in FindRoot
as follows
eq1 = Rationalize[eq, 10^-30];
sol3 =
FindRoot[Table[eq1[[i]] Conjugate[eq1[[i]]] == 0, {i, Length[eq1]}],
Table[{var[[i]], var[[i]] /. sol1}, {i, Length[var]}],
AccuracyGoal -> 18, PrecisionGoal -> 20, WorkingPrecision -> 40,
MaxIterations -> 10000]
During evaluation of In[63]:= FindRoot::cvmit: Failed to converge to the requested accuracy or precision within 10000 iterations.
Out[63]= {TT[t] -> 0.8410686705679302557765250318264307467021,
N2[t] -> 24.52500016238743443940870727557720488810,
Derivative[1][SS][
t] -> -8.834618704174150338967041790049095324767*10^-8,
Derivative[1][PP][
t] -> -1.472436452169582384601225318143779829260*10^-8,
Derivative[1][z][
t] -> -1.833168600179621480183988024023755387758*10^-10}
This solution not converges but we can check that eq1
satisfies with maximal error of $8.83\times 10^{-10}$
eq1 /. sol3
Out[]= {-1.833168600179621480*10^-10, \
-8.8346187050584847358310728019304536898*10^-10, -3.8972984275*10^-10,
0.*10^-21, 2.83945093*10^-11}