Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

enter image description here

share|improve this question
5  
This will work : Manipulate[ Plot[F[x] /. {C[1] -> a, C[2] -> b}, {x, -10, 10}], {a, 1, 6}, {b, -2, 5}] –  b.gatessucks Aug 23 '12 at 19:40
2  
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
1  
-> 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
1  
@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
2  
@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

2 Answers 2

up vote 6 down vote accepted

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"}]

enter image description here

For your more complicated case mentioned in the comments do this:

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

enter image description here

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"}]

enter image description here

share|improve this answer
    
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. –  DSaad Aug 23 '12 at 20:06
1  
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. –  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
1  
@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], 1, 6}, {C[2], -2, 5000}]
]

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.