Defining 2x2 Matrices with Variables for Solving DEs

  • Context: Mathematica 
  • Thread starter Thread starter McLaren Rulez
  • Start date Start date
  • Tags Tags
    Matrices Variables
Click For Summary

Discussion Overview

The discussion revolves around defining 2x2 matrices with variables in Mathematica for the purpose of solving differential equations (DEs). Participants explore different methods for representing these matrices and the implications of their choices on the solution process.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks a way to define a 2x2 matrix with four variables using a function in Mathematica, initially attempting matrix[a_, b_, c_, d_] := {{a, b}, {c,d}}.
  • Another participant explains the difference between = and := in Mathematica, suggesting that the latter is not suitable for immediate evaluation and may lead to confusion when trying to create matrices.
  • A participant considers rewriting each matrix differential equation as four independent equations, questioning whether this is the only approach or if there is a more efficient method to define matrices with variable entries.
  • There is a suggestion that avoiding subscripting variables may simplify the process of working with matrices in Mathematica.
  • Participants discuss the challenges of using Mathematica for complex queries and the potential benefits of simplifying the representation of problems.

Areas of Agreement / Disagreement

Participants express varying opinions on the best approach to defining matrices and solving differential equations in Mathematica. There is no consensus on a single method, and the discussion remains open to multiple perspectives.

Contextual Notes

Participants note limitations in the software's handling of matrix definitions and the potential complications arising from attempts to format queries for clarity. The discussion highlights the need for careful consideration of how variables and matrices are defined in Mathematica.

McLaren Rulez
Messages
289
Reaction score
3
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!
 
Last edited:
Physics news on Phys.org


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.
 


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


McLaren Rulez said:
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.

McLaren Rulez said:
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.
 


Thank you for your help.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K