# NDSolve with shooting method

Here are my equations:

eq1 = f'''[t] + (f[t] + g[t])*f''[t] - (f'[t])^2 == 0;
eq2 = g'''[t] + (f[t] + g[t])*g''[t] - (g'[t])^2 == 0;
eq3 = θ''[t] + (f[t] + g[t])*.7*θ'[t] == 0;    ic1 = f[0] == s;
ic2 = g[0] == 0;
ic3 = f'[0] == λ;
ic4 = g'[0] == λ1;
ic5 = θ[0] == 1;
ic6 = f'[η] == 0;
ic7 = g'[η] == 0;
ic8 = θ[η] == 0;
equations = {eq1, eq2, eq3};
initialconditions = {ic1, ic2, ic3, ic4, ic5, ic6, ic7, ic8};


and the solution method:

s4 = Table[{λ, f''[0] /.  NDSolve[Join[equations,
initialconditions /. {λ1 -> -0.5, η -> 5, s -> 4}], {f'', g', θ}, {t, 0, 20},
Method -> {"Shooting", "StartingInitialConditions" -> {f[0] == 4, f'[0] == -1,
f''[0] == 20, g[0] == 0, g'[0] == -0.5, g''[0] == 0, θ[0] == 1,
θ'[0] == 0}}][[1]]}, {λ, -3.70, 0, 0.01}];
s42 = Table[{λ, f''[0] /. NDSolve[Join[equations,
initialconditions /. {λ1 -> -0.5, η -> 20, s -> 4}], {f'', g, θ}, {t, 0, 20}][[1]]},
{λ, -3.70, 0, 0.1}]

ListPlot[{s4, s42},
PlotStyle -> {Red, {Red, Dashed}, Purple, {Purple, Dashed},
Cyan, {Cyan, Dashed}}, Joined -> True,
AxesLabel -> {Style ["\[Lambda]", 20], Style["f''(0)", 18]},
AspectRatio -> .7, PlotRange -> All]


and I get the following results:

how can I remove the noises to get the following results?

• It takes forever on my machine to execute s4. I don't why.
– zhk
Commented May 29, 2015 at 8:28
• It takes about 2 minute to solve. you can change {-3.7,0,0.01} to {-3.7,0,0.1} to speedup Commented May 29, 2015 at 9:20
• why are you not using the shooting method for the problematic solution? Commented May 29, 2015 at 20:43

The second curve is irregular, because the s42 calculation yields the desired second solution for some values of λ and the first solution for others. To obtain only the desired second solution, use

s42 = Table[{λ, f''[0] /. NDSolve[{equations,
initialconditions /. {λ1 -> -0.5, η -> 20, s -> 4}}, {f'', g', θ}, {t, 0, 20},
Method -> {"Shooting", "StartingInitialConditions" -> {f[0] == 4, f'[0] == -1,
f''[0] == .6 λ^2 - 6, g[0] == 0, g'[0] == -0.5, g''[0] == 1.6, θ[0] == 1,
θ'[0] == -2.1}}][[1]]}, {λ, -3.70, 0, 0.1}]


The challenge, of course, is to provide "StartingInitialConditions" for f''[0], g''[0], and θ'[0]. A bit of experimentation led to the f''[0] expression, while the second and third were obtained by computing their more or less constant values from the second solution for λ < -2.5.

Note that in the Question η -> 5 for s4, and η -> 20 for s42. Probably, the values should be the same for meaningful comparison. Also, computing s4 is exceedingly slow due to its 0.01 step size. Instead, I used this small step size only for -3.7 < λ < -3.5, and 0.1 otherwise. Finally, it is not necessary to use Join.

• Can you share the modified code. Pl. [email protected] Commented Feb 21, 2019 at 15:17
• @smohanty To what modified code are you referring? Commented Feb 21, 2019 at 16:24