8
$\begingroup$

OK guys, here's the thing, Mathematica does not return a solution for this system of differential equations:

DSolve[{p11'[t] == 2*p12[t] - (1/r)*p12[t]^2, 
p12'[t] == 
p22[t] - (w^2)*p11[t] - 2*z*w*p12[t] - (1/r)*p12[t]*p22[t], 
p22'[t] == -2*(w^2)*p12[t] - 
4*z*w*p22[t] - (1/r)*p22[t]^2 + (w^4)*q, p11[0] == 0, p12[0] == 0,
p22[0] == 0}, {p11[t], p12[t], p22[t]}, t]

Where z,w,r,q are parameters. Can anyone please try it on your system and tell me if you have the same problem?

I also tried with the NDSolve function

NDSolve[{p11'[t] == 2*p12[t] - (1/r)*p12[t]^2, 
p12'[t] == 
p22[t] - (w^2)*p11[t] - 2*z*w*p12[t] - (1/r)*p12[t]*p22[t], 
p22'[t] == -2*(w^2)*p12[t] - 
4*z*w*p22[t] - (1/r)*p22[t]^2 + (w^4)*q, p11[0] == 0, p12[0] == 0,
p22[0] == 0}, {p11[t], p12[t], p22[t]}, {t, 0, 10}]

but I get the error message:NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.

I greatly appreciate your help

(I use mathematica 8.0 and of course VariationalMethods is turned on)

$\endgroup$
  • $\begingroup$ "Mathematica does not return a solution for this system of differential equations" - this merely means that Mathematica doesn't know a lot of things, and your system of DEs is among those. $\endgroup$ – J. M. is in limbo Jun 20 '12 at 7:46
  • $\begingroup$ Why is it so obvious to turn on VariationalMethods (I guess you mean that you loaded the VariationalMethods package using << or Get)? NSolve or NDSolve don't need that. $\endgroup$ – Sjoerd C. de Vries Jun 20 '12 at 12:25
13
$\begingroup$

When using NDSolve all the parameters must have a numeric value.

solution[t_] = 
  With[{q = 1, r = 1, w = 1, z = 1}, 
   NDSolve[{p11'[t] == 2*p12[t] - (1/r)*p12[t]^2,
            p12'[t] == p22[t] - (w^2)*p11[t] - 2*z*w*p12[t] - (1/r)*p12[t] p22[t],
            p22'[t] == -2 (w^2)*p12[t] - 4*z*w*p22[t] - (1/r)*p22[t]^2 + (w^4)*q,
            p11[0] == 0,  p12[0] == 0, p22[0] == 0},
           {p11[t], p12[t], p22[t]}, {t, 0, 10}]][[1, All, 2]]

Plot[solution[t], {t, 0, 10}]

enter image description here

$\endgroup$
  • $\begingroup$ oh wow i didn't know that, i thought it could solve using these quantities as parameters. And the command [1, All, 2] in the end, what's it about? $\endgroup$ – Lazaros M. Jun 20 '12 at 7:55
  • $\begingroup$ @LazarosM. It's to get the functions from the solution to your system of equations, given in terms of rules. If you execute the With[...] block alone you will see. $\endgroup$ – b.gates.you.know.what Jun 20 '12 at 7:58
  • $\begingroup$ @LazarosM. Actually its [[1, All, 2]]. It's short for Part and it's about getting the solutions in a list for plotting $\endgroup$ – Ajasja Jun 20 '12 at 7:59
  • $\begingroup$ Guys thank you all very much, you have been extremely helpful! and thenks for the quick immediate responses $\endgroup$ – Lazaros M. Jun 20 '12 at 8:04
7
$\begingroup$

Just for fun, here is a version with Manipulate. So the values of parameters can be dynamically changed:

Manipulate[
 solution[t_] = 
  NDSolve[{p11'[t] == 2*p12[t] - (1/r)*p12[t]^2, 
     p12'[t] == 
      p22[t] - (w^2)*p11[t] - 2*z*w*p12[t] - (1/r)*p12[t] p22[t], 
     p22'[t] == -2 (w^2)*p12[t] - 
       4*z*w*p22[t] - (1/r)*p22[t]^2 + (w^4)*q, p11[0] == 0, 
     p12[0] == 0, p22[0] == 0}, {p11[t], p12[t], p22[t]}, {t, 0, 
     10}][[1, All, 2]];

 Plot[solution[t], {t, 0, 10}]
 , {{q, 1}, -10, 10, Appearance -> "Labeled"}
 , {{r, 1}, -10, 10, Appearance -> "Labeled"}
 , {{w, 1}, -10, 10, Appearance -> "Labeled"}
 , {{z, 1}, -10, 10, Appearance -> "Labeled"},
 TrackedSymbols :> {q, r, w, z}]

Manipulate

$\endgroup$

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.