# Solve matrix differential system and asymptotic solution in mathematica

1. Jul 11, 2011

### yashar

hi
i want to solve equation d/dt(A)=B which A and B are n by n matrices. the matrices variable is t which is time.

1-how i can solve this equation?

2-how i can obtain asymptotic solution for time=infinite?

i use some help of this topic but i get error in mathematica.

3-from what reference you obtain the right code? because i could not find the solution in mathematica documentation.

here is the mathematica file which i write the code within it.
http://www.mediafire.com/file/xk7k6ov74b999he/00.nb [Broken]

thanks

Last edited by a moderator: May 5, 2017
2. Jul 11, 2011

### Staff: Mentor

1) Remove MatrixForm from your definition of p. It should work then.
2) Use the Limit function as t->Infinity.
3) The problem was an error in your code. There isn't any documentation for that. At each step you need to check that your variables are defined correctly. The error message was that you didn't have a valid equation. That should have tipped you off that either d'[t] or p was incorrect.

3. Jul 12, 2011

### yashar

i manage to take limit .error was for lack of some assumptions on variables like positivity and ....

but i now have another question how i take limit from all 16 solution of the equation as a whole . without taking limit individually?

1-is there any method to take limit from all 16 solutions of the equation?
2-how can i have solutions of the equation in matrix form. i mean how solution of equation (d/dt)A=B which is A (a matrix) can be obtain in matrix form.

Last edited: Jul 12, 2011
4. Jul 12, 2011

### Staff: Mentor

Try Limit[Map[(#[t] /. (soln[[1]])) &, dd, {2}], t -> Infinity] but of course you will have to add the positivity and other assumptions in also.

5. Jul 13, 2011

### yashar

thanks
it works.

is there any reference for this code?

Code (Text):
Limit[Map[(#[t] /. (soln[[1]])) &, dd, {2}], t -> Infinity]
i want to understand the job of any part of it. like #[t] and /. and (soln[[1]]) and (soln[[1]]) and dd (which is the solution of equation) and {2} (why it is 2 not for example 4?!)

thanks again

6. Jul 13, 2011

### Staff: Mentor

Sure, every bit of my knowledge of Mathematica comes from reading the online documentation, which is very good. I almost never open Mathematica without hitting F1 at some point.

If you type # into the help browser you are brought to the entry on Slot which describes the usage of # in pure functions and has a direct link to the tutorial on pure functions. The tutorial even begins with an example using Map. I highly recommend reading it since pure functions in Mathematica fill the role of lambda functions in many other languages and are therefore very useful.

If you type /. in to the help browser you are brought to the ReplaceAll entry, which explains how to use a list of rules to change an expression. Again, there is a link to a good tutorial on transformation rules.

If you type [[ in to the help browser you are brought to the Part entry which explains how to access elements of a list. This is such a central part of the language that there are a bunch of tutorials. Most of which I have read at one time or another.

For {2}, that is an argument to Map, so if you type Map into the help browser you are given information on all of the arguments and examples. And, of course, useful links to good tutorials.

7. Jul 13, 2011

### Staff: Mentor

One other recommendation. When you are coding a project, start simple with things that you know the answer. E.g. your definition of p is what you want to know, but it is way too complicated for you to test and debug your code.

You should start with a simpler expression for p which you know the answer. Then develop and test your code at each step using that simple p until you get the answer that you know to be correct. Only then, once you know your code is good, run it on the complicated p.

8. Jul 13, 2011

### yashar

thanks a lot. that was very useful

9. Jul 15, 2011

### yashar

hi
how i modify below codes to solve problem numerically?
n = 4;
d[t_] = Array[Subscript[w, $][t] &, {n, n}]; dd = Array[Subscript[w,$] &, {n, n}];
soln = DSolve[LogicalExpand[d'[t] == p], Flatten@dd, t]

thanks

10. Jul 15, 2011

### Staff: Mentor

To solve it numerically you will need to use NDSolve. However, in order to use NDSolve will require a little more information than you have given above. Specifically, you will also need to provide the initial conditions and the initial time and the final time.

11. Jul 15, 2011

### yashar

hi
suppose initial condition is d[0]=IdentityMatrix[4] and initial time =0 and final time 11.

and another question:
when i use
n = 4;
d[t_] = Array[Subscript[w, $][t] &, {n, n}]; dd = Array[Subscript[w,$] &, {n, n}];
soln = DSolve[LogicalExpand[d'[t] == p], Flatten@dd, t]

the results are not in matrix form. i need the results in matrix form to take partial trace from them. how can i cast the results automatically in matrix form

12. Jul 15, 2011

### Staff: Mentor

Use the Partition function or dd/.soln

13. Jul 18, 2011

### yashar

hi i do not understand what you mean.

can you write an example for this two problem?

1-Numerically solving equation (d/dt)A=B . which A and B are n by n matrices with some initial condition for example A[0]=C.
after solving numerically i need to take partial trace and plot the resulting matrix elements. so solution of this equation {(d/dt)A=B} must be in matrix form.

2-for solving (d/dt)A=B analytically how i can obtain the result in matrix form for further computations like taking partial trace.

thank you very much

14. Jul 18, 2011

### Staff: Mentor

I will be travelling until Thursday. Have you looked at the online help for NDSolve and Partition? They should each have examples showing how to do it for similar problems.

15. Jul 20, 2011

### yashar

for this problem i use
Code (Text):
Map[(#[t] /. (soln[[1]])) &, dd, {2}]
and it works.

but still have problem 1

16. Jul 29, 2011

### yashar

can anybody help me?

17. Jul 29, 2011

### Staff: Mentor

Use Partition or dd/.soln