Hello, What I try to do is. Solve a system of differential equations and obtain a set of values. Compare these values, in this case when it becomes >1, then change accordingly one initial value (with an If ) and repeat. Let's say I would like to do this five times. The code I use is the following. Αpparently, I do not implement the If command correctly in the code.
I hope this makes sense.
Thank you for your effort.
Best regards,
A.
PS. I have also attached the file.
\[CapitalGamma] = 5/3;
c4 = 6;
smax = 50;
Rinit = 1.05;
\[Gamma]1 = 0.8;
\[Gamma]2 = 0.9;
t = Flatten@Table[i, {i, 1, 5, 1}];
\[Gamma]uinit = (\[Gamma]1 + \[Gamma]2)/2;
Sol1 = Quiet[
Catch[NDSolveValue[{D1[s] ==
2 (-1 + R[s]) R[
s] (-(-1 + \[CapitalGamma]) \[Gamma]u[s] +
c4 ((-1 + R[s]) R[s]^3)^((1 - \[CapitalGamma])/
2) (-2 + \[CapitalGamma]) \[CapitalGamma] \[Gamma]u[s]^(
2 - \[CapitalGamma]) +
c4 ((-1 + R[s]) R[s]^3)^((1 - \[CapitalGamma])/
2) (-1 + \[CapitalGamma]) \[CapitalGamma] \[Gamma]u[
s]^-\[CapitalGamma]),
N1[s] == -(1 + \[Gamma]u[s]^2) (1 - \[CapitalGamma] +
c4 (-1 + R[s])^(1/2 - \[CapitalGamma]/2)
R[s]^(-(3/2) (-1 + \[CapitalGamma])) (2 +
4 R[s] (-1 + \[CapitalGamma]) -
3 \[CapitalGamma]) \[CapitalGamma] \[Gamma]u[s]^(
1 - \[CapitalGamma])),
R'[s] == D1[s]/Sqrt[D1[s]^2 + N1[s]^2],
Derivative[1][\[Gamma]u][s] == N1[s]/Sqrt[D1[s]^2 + N1[s]^2],
R[0] == Rinit, \[Gamma]u[0] == \[Gamma]uinit,
WhenEvent[N1[s]* D1[s] == 0, Throw[{#, s, Abs[N1[s]/D1[s]]
, R[s]}]; "Stop Integration"]}, {R, \[Gamma]u}, {s, 0,
smax}]], NSDolveValue::noout] & /@ t
j = Select[Sol1, #[[3]] > 1 &][[All, {1, 2, 3, 4}]];
j[[All, 3]];
If[j[[3, 3]] > 1, \[Gamma]2 = \[Gamma]uinit]
If[j[[3, 3]] < 1, \[Gamma]1 = \[Gamma]uinit]
Attachments: