Here is my code.
s = NDSolve[{f'''[x] + f[x]*f''[x] == 0, f[0] == A, f'[0] == 0, f'[10] == 1}, f, x]
I want to plot f''[0]
with respect to A
in [0,3]
range. How can I plot this graph?
Here is my code.
s = NDSolve[{f'''[x] + f[x]*f''[x] == 0, f[0] == A, f'[0] == 0, f'[10] == 1}, f, x]
I want to plot f''[0]
with respect to A
in [0,3]
range. How can I plot this graph?
A simple way is sampling a few data points for different a
values:
pts = Table[
Module[{A = j},
s = NDSolve[{y'''[x] + y[x] y''[x] == 0, y[0] == A, y'[0] == 0, y'[10] == 1}, y, {x, 0, 10}];
Flatten@{j, y'''[0] /. s}
],
{j, 0., 3., 0.1}];
Then plot them as:
ListPlot[pts]
You can use ParametricNDSolveValue
for this task in two different ways. First, and more convenient way, is to
use
f''[val]
as the second argument ofParametricNDSolveValue
to get a function of the parametera
that gives the value of the functionf''
att==val
{pf0, pf1, pf5} = ParametricNDSolveValue[{f'''[x] + f[x]*f''[x] == 0, f[0] == a,
f'[0] == 0, f'[10] == 1}, #, {x, 0, 10}, {a}] & /@ {f''[0], f''[1], f''[5]};
Plot[{pf0[a], pf1[a], pf5[a]}, {a, 0, 1}, PlotStyle -> Thickness[.01],
ImageSize -> 400, PlotLegends -> Placed[LineLegend[{"f''[0]", "f''[1]", "f''[5]"},
LabelStyle -> Directive["Palette", 16], BaseStyle -> Thick,
LegendLayout -> "Row"], Above]]
Similarly, using f[1]
, and f'[1]
and f''[1]
as the second argument
{pf, fprm1, fprm2} = ParametricNDSolveValue[{f'''[x] + f[x]*f''[x] == 0, f[0] == a,
f'[0] == 0, f'[10] == 1}, #, {x, 0, 10}, {a}] & /@ {f[1], f'[1], f''[1]};
Plot[{pf[a], fprm1[a], fprm2[a]}, {a, 0, 1},
PlotStyle -> Thickness[.01], ImageSize -> 400,
PlotLegends -> Placed[LineLegend[{"f[1]", "f'[1]", "f''[1]"},
LabelStyle -> Directive["Palette", 16], BaseStyle -> Thick,
LegendLayout -> "Row"], Above]]
Alternatively, you can get a parametric solution for f
and take its derivative(s):
pf = ParametricNDSolveValue[{f'''[x] + f[x]*f''[x] == 0, f[0] == a,
f'[0] == 0, f'[10] == 1}, f, {x, 0, 10}, {a}];
Row[Plot[Evaluate[{pf[a][x], D[pf[a][x], {x, 1}], D[pf[a][x], {x, 2}]} /. x -> #],
{a, 0, 1}, PlotStyle -> Thickness[.01], ImageSize -> 350,
PlotLegends -> Placed[LineLegend[{"f[" <> ToString@# <> "]",
"f'[" <> ToString@# <> "]", "f''[" <> ToString@# <> "]"},
LabelStyle -> Directive["Palette", 20], BaseStyle -> Thick,
LegendLayout -> "Row"], Above]] & /@ {0, 1, 5}]
You need to set a value for $a$:
s = NDSolve[
{y'''[x] + y[x] y''[x] == 0,
y[0] == 1,
y'[0] == 0,
y'[10] == 1}, y, {x, 0, 10}]
{{y -> InterpolatingFunction[{{0., 10.}}, <>]}}
Plot[Evaluate[y[x] /. s], {x, 0, 10}]
Plot[Evaluate[y'''[x] /. s], {x, 0, 10}]