• Support PF! Buy your school textbooks, materials and every day products Here!

Solving a matrix differential equation in Mathematica

  • Thread starter Qubix
  • Start date
  • #1
82
1
I want to solve a differential equation of the form

d/dt (R) = B(t)

where R and B are two complex matrices, with time dependent functions as their coefficients.
I want to solve these 3x3 differential equations (ones on the diagonal are actually coupled) and to obtain a matrix form for R. So I must solve with DSolve , not numerical.

Any ideas?
 

Answers and Replies

  • #2
1,069
29
See if there are any mistakes in this idea

In[1]:= (*Make up some example data to have a concrete question*)
R = {{y[t], 2 y[t]^2}, {y[t], y[t]/2}};
B = {{-y[t], 4 y[t]}, {y[t], 2 y[t]}};
(*Now do some list hacking to rearrange the bits into the form you desire*)
Map[dsolve[#, y[t], t] &, MapThread[Equal, {Flatten[D[R, t]], Flatten[ B ] }]]

Out[3 ] = {dsolve[y'[t] == -y[t], y[t], t],
dsolve[4 y[t] y'[t] == 4 y[t], y[t], t],
dsolve[y'[t] == y[t], y[t], t],
dsolve[y'[t]/2 == 2 y[t], y[t], t]}

If all that appears to be giving you the equations you expect then you can change the dsolve into DSolve and do the actual calculations. If this isn't correct then provide a more specific simple example and we can work from that.

EDIT: D**n embedded formatting metacharacters had eaten part of the code. I think I've fixed that now. Sorry about that.
 
Last edited:
  • #3
82
1
Thanks Bill, it seems to work. I just have to extend the code you've given to suit something like:

A={{A00,A01,A02},{A10,A11,A12},{A20,A21,A22}}

and

B={{cA11-dA22 , eA01, fA02},{gA10, hA11+jA22, kA12},{lA20,mA21,nA11-oA22}}

where a,b,c,d... are simple coefficients and A00,A01... are the 9 time dependent functions.

So the differential equation is dA/dt = B

The way I modified your code is :

Map[dsolve[#, {A00[t],A01[t],A02[t],A10[t],A11[t],A12[t],A20[t],A21[t],A22[t]}, t] &, MapThread[Equal, {Flatten[D[R, t]], Flatten[ B ] }]]

The error i get is

DSolve::dsmsm: Built-in routines cannot solve this problem. There is an equation that involves none of the dependent variables or there is a dependent variable that does not appear in any equation.
 
Last edited:
  • #4
1,069
29
Are you trying to do a single DSolve for nine functions? If so then try something like this

R = {{y1[t], 2 y2[t]^2}, {y3[t], y4[t]/2}};
B = {{-y1[t], 4 y2[t]}, {y3[t], 2 y4[t]}};
dsolve[MapThread[Equal, {Flatten[D[R, t]], Flatten[B ]}], {y1[t], y2[t], y3[t], y4[t]}, t]

Or just post what your problem really is and we can get to the answer.
 
  • Like
Likes mariemarie
  • #5
82
1
Hmm, if I use this one, I only get one vector listing all 9 equations, but it does not solve them. The real problem would be too big to write here, that is why I posted just a simple example.
 
  • #6
1,069
29
Have you inspected the structure of the dsolve[{...},{...},t], verified that it is correct, then replaced dsolve with DSolve and finally found that DSolve cannot solve your system?

Or have you inspected the structure to verify that it is correct, but not then replaced the dsolve with DSolve?

I intentionally wrote dsolve for the example so you would be able to check the structure before DSolve would try to process the arguments without giving you any hint whether the problem was correctly set up first.
 
Last edited:
  • #7
82
1
Now it seems to be working. Thank you very much Bill. :)
 

Related Threads on Solving a matrix differential equation in Mathematica

Replies
10
Views
15K
Replies
1
Views
1K
Replies
8
Views
1K
Replies
2
Views
2K
  • Last Post
Replies
3
Views
937
  • Last Post
Replies
0
Views
1K
Replies
2
Views
1K
  • Last Post
Replies
8
Views
2K
  • Last Post
Replies
5
Views
3K
Top