two weeks ago, I post a question see, and I got its answer, however, I would like to vary the values: g from (0.02 to 0.07), R from (0.1 to 0.3),and k2 from (0.03 to 0.07) by an increment of 0.01 using for Do loop. Can you please help?
Answer
It is possible to use the following model for parametric studies.
p[Z0_, g0_, k0_, R0_] := Block[{Z = Z0, g = Rationalize[g0, 0],
k2 = Rationalize[k0, 0],
\[Epsilon] = 10^-4, R = Rationalize[R0, 0]},
ps = ParametricNDSolveValue[{y''[r] + 2 y'[r]/r == k2 Sinh[y[r]],
y[\[Epsilon]] == y0, y'[\[Epsilon]] == 0,
WhenEvent[r == 1, y'[r] -> y'[r] + Z g]}, {y,
y'}, {r, \[Epsilon], R}, {y0}, Method -> "StiffnessSwitching",
WorkingPrecision -> 20];
sol = FindRoot[Last[ps[y0]][R], {y0, -1},
Evaluated -> False][[1, 2]];
Plot[First[ps[sol]][r], {r, \[Epsilon], R}, AxesLabel -> {r, y},
PlotLabel ->
Grid[{{"Z", "g", "k2", "R"}, {Z0, g0, k0, R0}}, Frame -> All]]]
p1[Z0_, g0_, k0_, R0_] := Block[{Z = Z0, g = Rationalize[g0, 0],
k2 = Rationalize[k0, 0],
\[Epsilon] = 10^-4, R = Rationalize[R0, 0]},
ps = ParametricNDSolveValue[{y''[r] + 2 y'[r]/r == k2 Sinh[y[r]],
y[\[Epsilon]] == y0, y'[\[Epsilon]] == 0,
WhenEvent[r == 1, y'[r] -> y'[r] + Z g]}, {y,
y'}, {r, \[Epsilon], R}, {y0}, Method -> "StiffnessSwitching",
WorkingPrecision -> 20];
sol = FindRoot[Last[ps[y0]][R], {y0, -1},
Evaluated -> False][[1, 2]];
Plot[Last[ps[sol]][r], {r, \[Epsilon], R}, AxesLabel -> {r, y'},
PlotLabel ->
Grid[{{"Z", "g", "k2", "R"}, {Z0, g0, k0, R0}}, Frame -> All]]]
Two examples of using this code
Quiet[Table[
p[800, g, 0.0002, 1.5], {g, 0.02, 0.06, .02}]] // AbsoluteTiming
Quiet[Table[
p[800, .02, 0.0002, R], {R, 1.2, 1.7, .1}]] // AbsoluteTiming
Comments
Post a Comment