Setting up the systems - working with matrices

There are a lot of different ways to handle systems of differential equations in Mathematica.  The most simplistic method is to just enter them as lists of differential equations:

[Graphics:../Images/index_gr_112.gif]
[Graphics:../Images/index_gr_113.gif]

This method works (and is easy to understand), but starts to get kind of cumbersome for larger systems (and certainly doesn't win any cool points...).  Personally, I prefer to set systems up from the outset as matrix equations.

To do this, you need to know a few things about how Mathematica handles matrices and vectors.  As far as Mathematica is concerned, a vector is just a list of items: [Graphics:../Images/index_gr_114.gif]  A matrix is just a list of lists:  [Graphics:../Images/index_gr_115.gif], where each inside list is a row of the matrix. So this last matrix would look like:

[Graphics:../Images/index_gr_116.gif]
[Graphics:../Images/index_gr_117.gif]

In fact, you can enter matrices directly (so they actually look like matrices) by using the "Create Table/Matrix/Palette" command under the "Input" menu (then just choose "Matrix" and the number of rows/columns) or, if you need a 2 by 2 matrix, there is a button on the standard tool palette for this.

To multiply two matrices, you must use . between them; if you use implied multiplation (or the standard × symbol), Mathematica  won't use matrix multiplication.  So:

[Graphics:../Images/index_gr_118.gif]
[Graphics:../Images/index_gr_119.gif]

Or:

[Graphics:../Images/index_gr_120.gif]
[Graphics:../Images/index_gr_121.gif]
[Graphics:../Images/index_gr_122.gif]
[Graphics:../Images/index_gr_123.gif]

(Sticking //MatrixForm at the end of the line just makes the answer look nice. It isn't necessary.)

One other thing Mathematica does that is kind of nice is that it handles multiplication of a matrix times a vector properly (if you use .), even if the vector isn't really the right kind of vector (i.e., you can be sloppy about row vectors vs. column vectors).  We will take advantage of this to simplify some work that Mathematica would otherwise force you to do.  (I will treat all vectors as row vectors, even when it would be more correct to use column vectors.  Trust me, this simplifies things a lot...)

In order for vector equations to work correctly in Mathematica, you must first execute the following command (this is important, so pay attention):

[Graphics:../Images/index_gr_124.gif]

(If you are interested, this makes it so the == sign is "listable", i.e., it works with matrices and other lists.)

Now, let's pull all this together and start using matrix notation.  First, let's just set up a system of algebraic equations.  The system:  
[Graphics:../Images/index_gr_125.gif]
[Graphics:../Images/index_gr_126.gif]
[Graphics:../Images/index_gr_127.gif]
can be written in matrix form with the following definitions:

[Graphics:../Images/index_gr_128.gif]
[Graphics:../Images/index_gr_129.gif]

One note about notation:  For clarity sake (and to avoid using variable names that begin with capital letters), I will name all matrices beginning with an m (so mA, mC, mWhatever) and all vectors beginning with a v (vX, vSolution, vSomething).

So the system becomes:

[Graphics:../Images/index_gr_130.gif]
[Graphics:../Images/index_gr_131.gif]
[Graphics:../Images/index_gr_132.gif]
[Graphics:../Images/index_gr_133.gif]

So we can solve the system very easily this way.

Now, let's set up a system of differential equations.  Let's set up:
[Graphics:../Images/index_gr_134.gif]
[Graphics:../Images/index_gr_135.gif]
with initial conditions [Graphics:../Images/index_gr_136.gif].    

[Graphics:../Images/index_gr_137.gif]
[Graphics:../Images/index_gr_138.gif]
[Graphics:../Images/index_gr_139.gif]
[Graphics:../Images/index_gr_140.gif]
[Graphics:../Images/index_gr_141.gif]
[Graphics:../Images/index_gr_142.gif]
[Graphics:../Images/index_gr_143.gif]

Or, if you prefer to include the initial conditions in the solution:

[Graphics:../Images/index_gr_144.gif]
[Graphics:../Images/index_gr_145.gif]
[Graphics:../Images/index_gr_146.gif]
[Graphics:../Images/index_gr_147.gif]

A more complicated system might look something like this:

[Graphics:../Images/index_gr_148.gif]
[Graphics:../Images/index_gr_149.gif]
[Graphics:../Images/index_gr_150.gif]
[Graphics:../Images/index_gr_151.gif]
[Graphics:../Images/index_gr_152.gif]
[Graphics:../Images/index_gr_153.gif]
[Graphics:../Images/index_gr_154.gif]


Converted by Mathematica      July 20, 2003