Solving a differential equation with NDSolve and plotting it WITH the use of Manipulate

I want to solve, let's say, this differential equation:

y'[x]=y[x]^n

Given any initial condition (which I might want to manipulate too).

I want to plot the graph of this function while manipulating the exponential factor n. I tried something like this:

sol = NDSolve[{y'[x] == y[x]^n, y == 0}, y[x], x];
Manipulate[ Plot[Evaluate[y[x] /. sol], {x, -5, 5}], {n, 0, 2}]

But it does not work...

I'm really sorry, but I'm new to Mathematica so it can be a really simple thing. Already grateful for the help!

Manipulate[ Plot[y[x] /. sol[n], {x, 0, 2}, Evaluated -> True],
{n, 0, 4},
Initialization-> {sol@h_:= Quiet@NDSolve[{y'@x == y@x^h, y@0 == 1}, y, {x, 0, 2}]}] Just for fun and using DynamicModule and only looking at integer exponents:

DynamicModule[{p},
Framed[Column[{
Dynamic[With[{h = p},
sol =
First@Quiet[
DSolve[{y'[x] == y[x]^h, y == 1}, y[x], {x, 0, 2}]];
Plot[y[x] /. sol, {x, 0, 2}, Evaluated -> True,
PlotStyle -> Red,
Epilog -> Text[Style[y[x] /. sol, White], Center],
Frame -> True, FrameStyle -> White, PlotRange -> {0, 30},
ImageSize -> 350]]],
Row[{Style["Exponent", White, Bold], Spacer,
SetterBar[Dynamic[p], Range[0, 10]]}]}], RoundingRadius -> 20,
Background -> Black]] You are almost there. There are two things. One is to make the NDSolve syntax correctly. That is to give {x,0,5}instead of simply xin it, since NDSolve is a numeric solution and one needs to fix the limits for the variables.

The second is to put the solution of the equation under the Manipulate statement. Otherwise the solution will "not be aware" of your varying the n value:

Manipulate[
sol = NDSolve[{y'[x] == y[x]^n, y == 1}, y[x], {x, 0, 5}];
Plot[Evaluate[y[x] /. sol], {x, 0, 5}],
{n, 0, 2}] Have fun!

• Thanks for clear answer as always. In case you find the time, your input on this recent post would be very valuable mathematica.stackexchange.com/questions/166671/… Look forward to hearing from you. Thank you in any case. – user929304 Feb 26 '18 at 17:06
• @ user929304 Have a look into the question you mentioned above, I gave an answer. – Alexei Boulbitch Feb 27 '18 at 10:06