1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Solving a matrix differential equation in Mathematica

  1. Oct 27, 2014 #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?
  2. jcsd
  3. Oct 27, 2014 #2
    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: Oct 27, 2014
  4. Oct 28, 2014 #3
    Thanks Bill, it seems to work. I just have to extend the code you've given to suit something like:



    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: Oct 28, 2014
  5. Oct 28, 2014 #4
    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.
  6. Oct 29, 2014 #5
    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.
  7. Oct 29, 2014 #6
    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: Oct 29, 2014
  8. Oct 30, 2014 #7
    Now it seems to be working. Thank you very much Bill. :)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted