# Evaluate an ODE for several values of a coefficient and draw all the solutions in one plot

I want to draw one plot showing all the solutions the following ODE with different values of N. How can i do it?

s = NDSolve[{2 y'''[x] + (y[x]*y''[x]) == 0,
g''[x] + (0.5****N***y[x]*g'[x]) == 0,
g[0] == y[0] == 0, y'[0] == 0, y'[8] == 1, g[12] == 1}, {y, g}, {x, 0, 12}];

Plot[Evaluate[{g[x]} /. s], {x, 0, 12}, PlotStyle -> Automatic]

-
Welcome to Mathematica.SE! Note how I formatted your code - please do the same next time. Also: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, 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, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign – Vitaliy Kaurov Dec 11 '12 at 7:57

N is a function in Mathematica, so it is a bad idea to use it as a variable name. Let's use m instead. Define solution as function of m:

s[m_]:=NDSolve[{2 y'''[x] + (y[x] y''[x]) == 0,
g''[x] + (0.5*m*y[x]*g'[x]) == 0,
g[0] == y[0] == 0, y'[0] == 0, y'[8] == 1, g[12] == 1}, {y, g}, {x, 0, 12}]


Set values of m

m= Range[.1, 3, .1];


and plot solutions:

Plot[Evaluate[g[x] /. (s /@ m)], {x, 0, 12},
PlotStyle -> Directive[Thick, Opacity[.8]], Frame -> True, Axes -> False]


Or use interactive content:

alst = Plot[Evaluate[g[x] /. {s[.1], s[3], s[#]}], {x, 0, 12},
Frame -> True, Axes -> False, PlotRange -> {0, 1},
PlotStyle -> Directive[Thick, Opacity[.9]],
Filling -> {1 -> {2}}, PlotLabel -> "M = " <> ToString[#]] & /@ m;
ListAnimate[alst, AnimationRunning -> False, FrameMargins -> 0]


-
@NasserM.Abbasi good point ;) done. – Vitaliy Kaurov Dec 11 '12 at 9:08
Dear Vitaliy Kaurov thank you very much. another question. if i want to assign to m specific value not in range between any number. for example m={0.7,1,2,20,10,100,1000} something like how should i write the code then? – mehrzad Dec 11 '12 at 16:17
@user4969 as you just did - define m as m={0.7,1,2,20,10,100,1000} instead of using Range. Btw I'd recommend choosing more unique name than user4969, hard to remember people this way ;) – Vitaliy Kaurov Dec 11 '12 at 16:37

As it is already pointed out by Vitaliy Kaurov, N is a built-in function and should not be used as a variable. Besides, I'd like to mention new functions in version 9: ParametricNDSolve and ParametricNDSolveValue.

s = ParametricNDSolveValue[{2 y'''[x] + (y[x]*y''[x]) == 0,
g''[x] + (0.5*m*y[x]*g'[x]) == 0, g[0] == y[0] == 0, y'[0] == 0,
y'[8] == 1, g[12] == 1}, {y, g}, {x, 0, 12}, m]


ParametricFunction[<>]

For some given m, s[m] evaluated to ordinary InterpolatingFunction. So the plot can be written as:

Plot[Evaluate[Table[s[m][[2]][x], {m, .1, 3, .1}]], {x, 0, 12},
PlotStyle -> (ColorData["Rainbow"] /@ Rescale[Range[.1, 3, .1]])]
`

-