Register to reply

Defining matrix of variables in mathematica and solving matrix differential equation

Share this thread:
McLaren Rulez
#1
Nov14-12, 09:31 AM
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!
Phys.Org News Partner Science news on Phys.org
Scientists develop 'electronic nose' for rapid detection of C. diff infection
Why plants in the office make us more productive
Tesla Motors dealing as states play factory poker
Bill Simpson
#2
Nov14-12, 12:45 PM
P: 1,037
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.
McLaren Rulez
#3
Nov15-12, 02:26 AM
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

[tex]\frac{d}{dt}A=B[/tex]

I should simply write four equations of the form [itex]\frac{d}{dt}A_{ij}=B_{ij}[/itex]

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 :)

Bill Simpson
#4
Nov15-12, 03:23 AM
P: 1,037
Defining matrix of variables in mathematica and solving matrix differential equation

Quote Quote by McLaren Rulez View Post
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

[tex]\frac{d}{dt}A=B[/tex]

I should simply write four equations of the form [itex]\frac{d}{dt}A_{ij}=B_{ij}[/itex]
Yes. And avoiding the urge to subscript your variables will make your life easier too.

Quote Quote by McLaren Rulez View Post
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.
McLaren Rulez
#5
Nov15-12, 04:17 AM
P: 261
Thank you for your help.


Register to reply

Related Discussions
How to define vector function in Mathematica Math & Science Software 3
Define a function via numerical integration in Mathematica Math & Science Software 6
How to define local variables and constants in mathematica Math & Science Software 3
Define the matrix? Calculus & Beyond Homework 2
Define coefficients for system of equations with 3 variables Calculus & Beyond Homework 13