Original:
I am running the following code to find the root of F , T and MM, here is an example
L = 10; l = L*(3/10); DD = 1; mu = 1; sol =
ParametricNDSolve[{\[Phi]1''[s] - (T - F)*Sin[\[Phi]1[s]] ==
0, \[Phi]2''[s] - T*Sin[\[Phi]2[s]] == 0, \[Phi]1[0] ==
0, \[Phi]2'[L] == MM, \[Phi]1[l] == \[Phi]2[l] ==
ArcTan[1/mu]}, {\[Phi]1, \[Phi]2}, {s, 0, L}, {T, F, MM}];
m1[s_, T_, F_, MM_] :=
Evaluate[Evaluate[\[Phi]1[T, F, MM] /. sol][s]];
m2[s_, T_, F_, MM_] :=
Evaluate[Evaluate[\[Phi]2[T, F, MM] /. sol][s]];
dm1[s_, T_, F_, MM_] := Evaluate[D[m1[s, T, F, MM], s]];
dm2[s_, T_, F_, MM_] := Evaluate[D[m2[s, T, F, MM], s]];
BC1[T_?NumericQ, F_?NumericQ, MM_?NumericQ] :=
NIntegrate[Cos[m1[s, T, F, MM]], {s, 0, l}] - DD;
BC2[T_?NumericQ, F_?NumericQ, MM_?NumericQ] := -dm1[l, T, F, MM] -
T*(NIntegrate[Sin[m2[s, T, F, MM]], {s, l, L}]) + MM;
BC3[T_?NumericQ, F_?NumericQ, MM_?NumericQ] := m2[L, T, F, MM]; sol2 =
Monitor[
FindRoot[{BC1[T, F, MM] == 0, BC2[T, F, MM] == 0,
BC3[T, F, MM] == 0}, {{T, 1}, {F, 1}, {MM, 1}}], {T, F, MM}]
I've noticed that it takes quite a long time to get a response, and there's no assurance of the solution's accuracy. It's worth noting that the parameter DD can range between 0.01 and 2, and this makes the code's performance decline further when DD is small.
I'm seeking advice on techniques that can improve the speed and accuracy of the FindRoot function. Thanks a lot!
Update1:
I have removed the variable MM because it seems unnecessary, and the boundary conditions have also been changed for simplicity.Here is my updated code:
L = 10; l = L*(3/10); DD = 0.1; mu = 1;
sol =
ParametricNDSolve[{ϕ1''[s] - (T - F)*Sin[ϕ1[s]] ==
0, ϕ2''[s] - T*Sin[ϕ2[s]] == 0, ϕ1[0] ==
0, ϕ2'[L] == 0, ϕ1[l] == ϕ2[l] ==
ArcTan[1/mu]}, {ϕ1, ϕ2}, {s, 0, L}, {T, F}];
m1[s_, T_, F_] :=
Evaluate[Evaluate[ϕ1[T, F] /. sol][s]];
m2[s_, T_, F_] :=
Evaluate[Evaluate[ϕ2[T, F] /. sol][s]];
dm1[s_, T_, F_] := Evaluate[D[m1[s, T, F], s]];
dm2[s_, T_, F_] := Evaluate[D[m2[s, T, F], s]];
BC1[T_?NumericQ, F_?NumericQ] :=
NIntegrate[Cos[m1[s, T, F]], {s, 0, l}] - DD;
BC2[T_?NumericQ, F_?NumericQ] := -dm1[l, T, F] + dm2[l, T, F];
sol2 =
Monitor[
FindRoot[{BC1[T, F] == 0, BC2[T, F] == 0}, {{T, 1}, {F, 1}}], {T, F}]
Moreover, define a Piecewise function which is the conbination of ϕ1 and ϕ2,
fin[s_] := Piecewise[{{ϕ1[s], 0 <= s < l}, {ϕ2[s], l <= s <= L}}];
Since for different initial values used in Findroot, we can get different ϕ1 and ϕ2. However, the shape of fin[s] shown in the following figure is actually my goal.
Update2:
I especially need the results in condition of smaller DD and l. Such as
l = L*(2/100); DD = 0.1;
or even at a more extreme one
l = L*(2/1000); DD = 0.01;
I’m curious about what causes such difficulty in solving these equations at this condition in function FindRoot
and NDSolve
. Are there any techniques that can help improve this situation?
$\]Phi\1$` and `\[Phi]2` except for computing `\[Phi]1'` and `\[Phi]2'`. Why don't you instruct `ParametricNDSolve` to return `\[Phi]1'` and `\[Phi]2'` rather then `\[Phi]1` and `\[Phi]2` ?
$\endgroup$\[Phi]1
and\[Phi]2
is not unique, it will depend on the initial value of the solution and converge to different results. $\endgroup$ParametricNDSolveValue[ {ode$[k, z, p, {q, Mm, Rm}, \[CapitalLambda]] == 0, \[Phi][0] == 1, \[Phi]'[0] == 0} , {\[Phi]'[zR$], \[Phi][zR$]} , {z, 0, (1 + 0* 10^-7) zR$} , {{p, 0, pmx}, {\[CapitalLambda], 1, 500}} (*,Method->{"StiffnessSwitching"} ,Method->{"EquationSimplification"->"Residual"}*)
] $\endgroup$