1
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Commented Apr 25, 2015 at 5:14

3 Answers 3

0
$\begingroup$

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]

enter image description here

$\endgroup$
3
$\begingroup$

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 of ParametricNDSolveValue to get a function of the parameter a that gives the value of the function f'' at t==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]]

enter image description here

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]]

enter image description here

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}]

enter image description here

$\endgroup$
-1
$\begingroup$

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}]

enter image description here

Plot[Evaluate[y'''[x] /. s], {x, 0, 10}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.