# Defining matrix of variables in mathematica and solving matrix differential equation

by McLaren Rulez
Tags: defining, differential, equation, mathematica, matrix, solving, variables
 P: 261 Hi, I have a bunch of closed differential equations that I want to solve. The variables of the DEs are 2x2 matrices. So, I want to enter some 2x2 matrices of variables and then use NDSolve to get the solution. How should I define a 2x2 matrix with four variables inside it? I tried matrix[a_, b_, c_, d_] := {{a, b}, {c,d}} but this doesn't work. Rather embarassingly, I can't find the solution after quite a bit of googling. Thank you for your help!
 P: 935 In Mathematica = and := are very different things. := means, and this is way too simplified but you almost certainly don't want to know all the ugly details, that sometime in the future if you ever use matrix[p,q,r,s] THEN you replace it with the right hand side {{p,q},{r,s}}. But until that future gets here := just tells Mathematica to remember that direction and do nothing until then. I will warn you, the more anyone wants to "desktop publish" their problem, the more desperately they want to have everything in 2-d notation, the more problems they are likely going to find in trying to actually get a useful answer out of Mathematica. If I were going to try to get an answer to your differential equations I would manually translate the whole mess into a form that looks very much like the simplest examples that you find in the help system. I've found that is the quickest path to a hopefully correct and useful answer.
 P: 261 Thank you for the reply Bill. So, what you're saying is that I should simply write out each matrix DE as four independent DEs? For instance if I have a very simple example $$\frac{d}{dt}A=B$$ I should simply write four equations of the form $\frac{d}{dt}A_{ij}=B_{ij}$ This can indeed be done (and for me, it's not too bad since they are only 2x2 matrices) but I was wondering if there was an easier way to tell mathematica to create a matrix that has all its entries as variables. The reason I thought matrix[a_, b_, c_, d_] := {{a, b}, {c,d}} might work was because it worked for one variable. If I try matrix[a_] := {{a, 2}, {3,4}}, it understands that a is a variable so the input of matrix[1] gives the output {{1, 2}, {3,4}} and so on. It's not that I am lazy to write it out, I just wanted to see if there was a nicer solution. Thank you :)
P: 935

## Defining matrix of variables in mathematica and solving matrix differential equation

 Quote by McLaren Rulez Thank you for the reply Bill. So, what you're saying is that I should simply write out each matrix DE as four independent DEs? For instance if I have a very simple example $$\frac{d}{dt}A=B$$ I should simply write four equations of the form $\frac{d}{dt}A_{ij}=B_{ij}$
Yes. And avoiding the urge to subscript your variables will make your life easier too.

 Quote by McLaren Rulez This can indeed be done (and for me, it's not too bad since they are only 2x2 matrices) but I was wondering if there was an easier way to tell mathematica to create a matrix that has all its entries as variables. The reason I thought matrix[a_, b_, c_, d_] := {{a, b}, {c,d}} might work was because it worked for one variable. If I try matrix[a_] := {{a, 2}, {3,4}}, it understands that a is a variable so the input of matrix[1] gives the output {{1, 2}, {3,4}} and so on. It's not that I am lazy to write it out, I just wanted to see if there was a nicer solution. Thank you :)
You can write function definitions to create matricies and vectors. That is not a problem. But usually the more you try to "desktop publish" the queries you are giving Mathematica the more difficulty you will have.

Mathematica, like many other pieces of software, started out as a command line driven tool. Only later did they try to glue on desktop publishing and that is not uniformly implemented.

You are certainly free to try giving matricies of equations to DSolve. Give it a good serious try. Then report how well that worked.
 P: 261 Thank you for your help.

 Related Discussions Math & Science Software 3 Math & Science Software 6 Math & Science Software 3 Calculus & Beyond Homework 2 Calculus & Beyond Homework 13