1
$\begingroup$

I tried to solve system of ODEs, but something was wrong.

Clear[P]
Clear[A]
A = {1, 0, 0}
P[t_] = {P1[t], P2[t], P3[t]}
Q[t_] = {Q1[t], Q2[t], Q3[t]}
sol3 = DSolve[{P'[t] == Cross[A, Q[t]], Q'[t] == Cross[A, P[t]], 
  P[0] == {0.5, 0.5, 0.3}, Q[0] == {0.1, 0.2, 0.3}}, {P[t], Q[t]}, t]

The result is

 DSolve::dsfun: {P1[t],P2[t],P3[t]} cannot be used as a function. >> 

What interesting for me is that when I try to solve only one equation (not a system), everything is OK:

sol2 = DSolve[{P'[t] == Cross[A, P[t]], P[0] == {0.5, 0.5, 0.3}}, 
  P[t], t]
  {{P1[t] -> 0.5, P2[t] -> 0.5 Cos[t] - 0.3 Sin[t], 
  P3[t] -> 0.3 Cos[t] + 0.5 Sin[t]}}

I don't understand how it works...

$\endgroup$

1 Answer 1

2
$\begingroup$

Update:

Threading is not needed, thanks to comment by Michael below. Both solution work ofcourse, but Michael's sugestion is simpler, just Flatten the list if dependent variables:

Clear[P, A, t]
A = {1, 0, 0}
P[t_] = {P1[t], P2[t], P3[t]}
Q[t_] = {Q1[t], Q2[t], Q3[t]}
sol3 = DSolve[{P'[t] == Cross[A, Q[t]], Q'[t] == Cross[A, P[t]], 
  P[0] == {0.5, 0.5, 0.3}, Q[0] == {0.1, 0.2, 0.3}}, Flatten@{P[t], Q[t]}, t]

Mathematica graphics

Original answer

Need to thread the equations

Clear[P, A, t]
A = {1, 0, 0}
P[t_] := {P1[t], P2[t], P3[t]}
Q[t_] := {Q1[t], Q2[t], Q3[t]}
eq = {Thread[P'[t] == Cross[A, Q[t]]], Thread[Q'[t] == Cross[A, P[t]]]}
ic = {Thread[P[0] == {0.5, 0.5, 0.3}], Thread[Q[0] == {0.1, 0.2, 0.3}]}
sol3 = DSolve[Flatten@{eq, ic}, Flatten@{P[t], Q[t]}, t]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ Thanks, it works. But why do I need to do this? And why does it work with one equation? $\endgroup$
    – newt
    Mar 8, 2015 at 7:20
  • $\begingroup$ @newt Actually the only necessary change is to flatten the list of functions: Flatten@{P[t], Q[t]}. Now that's because DSolve is not programmed to construct arbitrary expressions in terms of the solutions; in particular, it thinks you want two functions, each of which is a vector of the form {P1[t], P2[t], P3[t]} composed of three solutions -- or rather, because {P1[t], P2[t], P3[t]} is not of the form symbol or symbol[t]. $\endgroup$
    – Michael E2
    Mar 8, 2015 at 17:45
  • $\begingroup$ @MichaelE2 ok, thanks $\endgroup$
    – newt
    Mar 9, 2015 at 6:15
  • $\begingroup$ @Nasser yes, thanks, I got it. $\endgroup$
    – newt
    Mar 10, 2015 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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