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 am trying to solve six connected differential equations. This is my code:

Clear[Solution,P1,P2,P3,Pbar1,Pbar2,Pbar3,tmax];
tmax=2;
Solution=NDSolve[Rationalize @ {
P1'[t]==-0.01 0.99995 P2[t]-Pbar2[t] P3[t]+Pbar3[t] P2[t],
P2'[t]==-0.01(-0.99995 P1[t]-0.01 P3[t])-Pbar3[t] P1[t]+Pbar1[t] P3[t],
P3'[t]==-0.01 0.01 P2[t]-Pbar1[t] P2[t]+Pbar2[t] P1[t],

Pbar1'[t]==0.01 0.99995 Pbar2[t]+P2[t] Pbar3[t]-P3[t] Pbar2[t],
Pbar2'[t]==-0.01(-0.99995 Pbar1[t]-0.01 Pbar3[t])+P3[t] Pbar1[t]-P1[t] Pbar3[t],
Pbar3'[t]==-0.01 0.01 Pbar2[t]+P1[t] Pbar2[t]-P2[t] Pbar1[t],

P1[0]==0,P2[0]==0,P3[0]==1,Pbar1[0]==0,Pbar2[0]==0,Pbar3[0]==1},

{P1[t],P2[t],P3[t],Pbar1[t],Pbar2[t],Pbar3[t]},{t,0,tmax}]

No errors and I get the normal output. There is something wrong with it, because the plot doesn't look like I want it to. That is not your problem, but when I try to check the solution by:

P3[0]/.Solution

I get

{P3[0]}

when I expect to get

{1}

or something like that.

Does anyone know what's wrong?

share|improve this question
    
The mistake is in the second argument of NDSolve. It should be {P1, P2, P3, Pbar1, Pbar2, Pbar3}, without the [t] arguments. Also, you don't need Rationalize here, but that's not a mistake. Since NDSolve uses numerical methods, it's okay to pass it inexact numbers. –  Szabolcs Feb 10 at 17:24
add comment

1 Answer 1

up vote 1 down vote accepted

In addition to what Szabolcs wrote, you mentioned that the solution doesn't look like what you want it to be. Here is the solution using tmax = 2:

tmax = 2;
s = NDSolve[{P1'[t] == -0.01 0.99995 P2[t] - Pbar2[t] P3[t] + 
      Pbar3[t] P2[t], 
    P2'[t] == -0.01 (-0.99995 P1[t] - 0.01 P3[t]) - Pbar3[t] P1[t] + 
      Pbar1[t] P3[t], 
    P3'[t] == -0.01 0.01 P2[t] - Pbar1[t] P2[t] + Pbar2[t] P1[t], 
    Pbar1'[t] == 
     0.01 0.99995 Pbar2[t] + P2[t] Pbar3[t] - P3[t] Pbar2[t], 
    Pbar2'[t] == -0.01 (-0.99995 Pbar1[t] - 0.01 Pbar3[t]) + 
      P3[t] Pbar1[t] - P1[t] Pbar3[t], 
    Pbar3'[t] == -0.01 0.01 Pbar2[t] + P1[t] Pbar2[t] - 
      P2[t] Pbar1[t], P1[0] == 0, P2[0] == 0, P3[0] == 1, 
    Pbar1[0] == 0, Pbar2[0] == 0, Pbar3[0] == 1}, {P1, P2, P3, Pbar1, 
    Pbar2, Pbar3}, {t, 0, tmax}][[1]]
Plot[{P1[t], P2[t], P3[t], Pbar1[t], Pbar2[t], Pbar3[t]} /. Solution, {t, 0, tmax}]

enter image description here

And here it is using tmax = 300:

Plot[{P1[t], P2[t], P3[t], Pbar1[t], Pbar2[t], Pbar3[t]} /. Solution, {t, 0, tmax}]

enter image description here

Is this the behavior you are looking for?

share|improve this answer
    
Why don't you include the solution from the comment into the answer, to make it complete? –  Szabolcs Feb 10 at 19:09
    
Added in the correction. –  DumpsterDoofus Feb 10 at 19:11
    
As messy as it may look, yes. That looks more like it! Thank you. –  user12291 Feb 11 at 8:10
add comment

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.