# How to get solution from DSolve

How to get the solution from DSolve in such way that there is no need to copy the result.

When for example solving:

f[x_, y_] := a y + x^2
DSolve[{D[y[x], x] == f[x, y[x]], y == c}, y[x], x]


I get the solution:

{{y[x] -> (-2 + 2 E^(a x) + a^3 c E^(a x) - 2 a x - a^2 x^2)/a^3}}


How can I make a function of this let's say sol[x] so I can use it in such context:

Manipulate[
Plot[sol[x], {x, 0, 5}], {a, -5, 5}, {c, -5, 5}]


EDIT: not interested in:

sol[x_, a_, c_] =
y[x] /. DSolve[{D[y[x], x] == f[x, y[x]], y == c}, y[x], x]

• You mean DSolveValue? – xzczd Jul 31 '14 at 7:30
• Not really, as Manipulate does not work with it as well. I can always stay with sol[x_,a_,c_] version. Thanks anyway. – Misery Jul 31 '14 at 7:45
• Well, then have you considered DSolveValue[……] (* start a new line *) Manipulate[Plot[%, {x, 0, 5}], {a, -5, 5}, {c, -5, 5}]? – xzczd Jul 31 '14 at 8:36
• @xzczd Why do not you give this as an answer? – Alexei Boulbitch Jul 31 '14 at 9:16
• @AlexeiBoulbitch Because I'm not sure if this is what OP wants , % is surely not a function :) – xzczd Jul 31 '14 at 10:37

Just to add a bit to the xzczd answer given in a form of a comment above. In earlier Mma versions (that might be your case) it can be done as follows:

    f[x_, y_] := a y + x^2
ss = DSolve[{D[y[x], x] == f[x, y[x]], y == c}, y, x][[1, 1]]


yielding this:

(*  y -> Function[{x}, (-2 + 2 E^(a x) + a^3 c E^(a x) - 2 a x - a^2 x^2)/
a^3]    *)


Then you can Manipulate/Plot it using the following construct:

    Manipulate[
Plot[Evaluate[y[x] /. ss /. {a -> a1, c -> c1}], {x, 0, 5}], {a1, -5,
5}, {c1, -5, 5}]


Have fun!