# 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, 6}, {C, -2, 5}]


the result of the equation is :

x + x^2/2 + E^x C + C


but I don't get any Curve on the display. • This will work : Manipulate[ Plot[F[x] /. {C -> a, C -> b}, {x, -10, 10}], {a, 1, 6}, {b, -2, 5}] – b.gates.you.know.what Aug 23 '12 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. – stevenvh Aug 23 '12 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 (:>). – rcollyer Aug 23 '12 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. – rcollyer Aug 23 '12 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. :) – rcollyer Aug 23 '12 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 == a, y' == 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 == a, y' == b, z == 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 -> a, C -> b}, G[x] /. {C -> a, C -> a}}, {x, -10, 10}], {a, -10, 10}, {b, -10, 10}] still I have the same problem like above. – DSaad Aug 23 '12 at 20:06
• G[x] and F[x] contain another constant, C, so you need to set that to some value if you want to Plot them: Manipulate[Plot[{F[x], G[x]} /. {C -> a, C -> b, C-> 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. – ecoxlinux Aug 23 '12 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 ;-) – Vitaliy Kaurov Aug 23 '12 at 20:21
• @VitaliyKaurov I understand your version but I don't how to find the a and b and c. – DSaad Aug 23 '12 at 20:27
• @DSaad I updated the answer – Vitaliy Kaurov Aug 24 '12 at 6:30

For a simple fix, does this behave as expected?

With[{fx = F[x]},
Manipulate[Plot[fx, {x, -10, 10}, PlotRange -> All], {C, 1, 6}, {C, -2, 5000}]
]


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

I'd still choose Vitaliy's method I think.