Manipulate a Differential Equation result

I want to Manipulate the result of Differential Equation like :

F[x_] = y[x] /. First@DSolve[x - y'[x] + y''[x] == 0, y[x], x]
Manipulate[Plot[F[x], {x, -10, 10}], {C[1], 1, 6}, {C[2], -2, 5}]


the result of the equation is :

x + x^2/2 + E^x C[1] + C[2]


but I don't get any Curve on the display.

• This will work : Manipulate[ Plot[F[x] /. {C[1] -> a, C[2] -> b}, {x, -10, 10}], {a, 1, 6}, {b, -2, 5}] Aug 23, 2012 at 19:40
• Why do you guys so often answer in comments instead of an answer? b.gatessucks's answer may be brief, but at least 4 users found it useful in only 9 minutes time. Aug 23, 2012 at 19:53
• -> is the operator form of Rule. When used in conjunction with ReplaceAll (/.) (or an of the replace functions), the left-hand side (LHS) of the Rule is transformed into the right-hand side. Compare this to RuleDelayed (:>). Aug 23, 2012 at 19:55
• @stevenvh effort. Sometimes it is just easier to post a hint in a comment, then have to explain things in an answer. So, just laziness. Aug 23, 2012 at 19:56
• @stevenvh the fundamental working principal of a software engineer. Boss: "Why did you spend 3 weeks automating a 10 minute job?" SWE: "So, I wouldn't have to do it ever again." I've spent a lot of time automating such tasks. :) Aug 23, 2012 at 20:30

There are many fixes to this issue. I would recommend formulating problem from the start in terms of your constants. So you know exactly what constants mean.

F[x_, a_, b_] = y[x]
/. First@ DSolve[{x - y'[x] + y''[x] == 0, y[0] == a, y'[0] == b}, y[x], x];

Manipulate[Plot[F[x, a, b], {x, -10, 10}, PlotLabel -> F[x, a, b]],
{{a, -4, "initial function"}, -10, 10, Appearance -> "Labeled"},
{{b, .96, "initial 1st derivative"}, .5, 1.5, Appearance -> "Labeled"}]


G[x_, a_, b_, c_] = {y[x], z[x]} /. First@DSolve[{y'[x] - 8*z'[x] == x^2,
z''[x] == x - y[x], y[0] == a, y'[0] == b, z[0] == c}, {y[x], z[x]}, x] // FullSimplify;

G[x, a, b, c] // Column // TraditionalForm


Manipulate[Plot[Evaluate@G[x, a, b, c], {x, -5, 5}, Filling -> 0,
PlotLabel -> Column[G[x, a, b, c]]],
{{a, 8, "initial y"}, -10, 10,Appearance -> "Labeled"},
{{b, 0, "initial y'"}, -10, 10, Appearance -> "Labeled"},
{{c, 0, "initial z"}, -10, 10, Appearance -> "Labeled"}]


• I have another question what should I do when I have more complex equation like this : F[x_] = y[x] /. First@DSolve[{y'[x] - 8*z'[x] == x^2, z''[x] == x - y[x]}, {y[x], z[x]}, x]; G[x_] = z[x] /. First@DSolve[{y'[x] - 8*z'[x] == x^2, z''[x] == x - y[x]}, {y[x], z[x]}, x] I want to manipulate both of them at the same time , like this : Manipulate[ Plot[{F[x] /. {C[1] -> a, C[2] -> b}, G[x] /. {C[1] -> a, C[2] -> a}}, {x, -10, 10}], {a, -10, 10}, {b, -10, 10}] still I have the same problem like above. Aug 23, 2012 at 20:06
• G[x] and F[x] contain another constant, C[3], so you need to set that to some value if you want to Plot them: Manipulate[Plot[{F[x], G[x]} /. {C[1] -> a, C[2] -> b, C[3]-> c}, {x, -10, 10}], {a, -10, 10}, {b, -10, 10}, {c, -10, 10}]. You can always look at the results of your assignments to check the generated constants. Aug 23, 2012 at 20:16
• @DSaad you just have to do the same thing for all functions and constants that you use. BTW the code that you show in the comment is different from my implementation. It's b.gatessucks version . My version is different. I am kind of not sure if you understood my answer in the 1st place ;-) Aug 23, 2012 at 20:21
• @VitaliyKaurov I understand your version but I don't how to find the a and b and c. Aug 23, 2012 at 20:27
With[{fx = F[x]},

I changed the range of C[2] so that its effect would be noticeable.