1
$\begingroup$

I have defined a set of differential equations stored in sol and I'd like to plot them while being able to change the parameters. I've tried it like so:

    Manipulate[
    sol = DSolve[{Derivative[1][x][t] == -b x[t], 
    Derivative[1][p][t] == -(1 - r) p[t] + b x[t], x[0] == 100, 
    p[0] == 10}, {x[t], p[t]}, t], 
  Plot[Evaluate[p[t] /. sol[[1, 1]], {t, 0, 10}], {b, 0, 1}, {r, 0, 1}]
 ]

but I'm receiving the error message:

"Manipulate argument Plot[Evaluate[p[t]/. \ sol[[1,1]],{t,0,10}],{b,0,1},{r,0,1}] does not have the correct form \ for a variable specification."

Any idea how I can fix this? I'd be much appreciated.

$\endgroup$
4
$\begingroup$

You have a few syntax errors. See below for corrected code:

Manipulate[
 sol = DSolve[
        {Derivative[1][x][t] == -b x[t], 
         Derivative[1][p][t] == -(1 - r) p[t] + b x[t], 
         x[0] == 100, p[0] == 10},
        {x[t], p[t]}, t
       ]; 
 Plot[Evaluate[p[t] /. sol[[1, 1]]], {t, 0, 10}],
 {b, 0, 1}, {r, 0, 1}
]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Yeah, I couldn't because I didn't have enough "points". I have now so it's done :) $\endgroup$ – phytab Jul 7 '16 at 14:57
  • $\begingroup$ @phytab Thank you! $\endgroup$ – MarcoB Jul 7 '16 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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