Matrix Operations in MS Excel

advertisement
SonshineCS MathSolutions
http://www.sonshinecs.com/mathsolutions/
Matrix Operations in MS Excel
MS Excel version used for this document:
Microsoft Office Excel 2007
Note: You can get detailed help for any topic in Excel, by clicking the Help button in the upper
right corner of the Excel window
. Clicking Help will open a window where you can
Search for any topic you need help with:
1. Open MS Excel:
2. Create a table to contain the data representing the matrix upon which you wish to operate.
For example, suppose you want to solve the following three linear simultaneous equations
using the matrix functions available in Excel:
x1 
 4
x2
3 x1  2 x2
 5 x3
 10
2 x1

 5
x3
Inserting coefficients for all of the unknowns ( x 's ) in the equations, they would look like
this:
1 x1  1 x2
 0 x3
 4
3 x1  2 x2
 5 x3
 10
2 x1  0 x2
 1 x3
 5
In matrix form, these equations can be represented by a coefficient matrix A , a righthand-side vector B , and an unknown vector X :
AX = B
1 1 0 
 x1 
 4 




where A   3 2 5  , X   x2  , and B  10 
 2 0 1 
 x3 
 5 
In matrix form, the solution to this system of equations can be represented by the matrix
equation:
X = A-1B where A-1 is the inverse of the A matrix.
At this point, we offer the above statement without proof or explanation, other than to say
that, based on this relationship, if we can find the inverse of the A matrix, and if we can
multiply the inverted A matrix ( A-1 ) times the B vector, we will have the X vector which
is the solution to the problem; that is, the X vector is the values of the unknown x 's
satisfying the given equations.
MS Excel contains the matrix functions that allow us to solve the equations as we’ve
outlined above.
In Excel, create the arrays (tables) representing the A matrix and the B vector:
A=
1
3
2
-1
2
0
0
5
1
B=
-4
10
5
3. Calculate the inverse of the A matrix using the MINVERSE() function in Excel. Since the
inverse of a 3x3 matrix is another 3x3 matrix, mark off the 3x3 cells in Excel that will
receive the results of the matrix inversion:
Then enter the command to compute the inverse:
Note that MINVERSE is the Excel function that will calculate the inverse of the A matrix
and the range of cells in the parentheses of the function (that is, the argument of the
function) is the range of cells that contains the A matrix.
THIS STEP IN ENTERING THE FUNCTION IS CRITICAL. Since the output of the
MINVERSE function is an array of values rather than just one single value, you enter the
function by holding down the <Ctrl> and <Shift> keys and then pressing the <Enter> key.
The result will be the inverse of the A matrix in the cells that you marked:
Note that if you press only the <Enter> to enter the function, you will get only a single
value in the first cell rather than the array representing the inverted A matrix. For
example, pressing only the <Enter> key (rather than <Ctrl><Shift> and <Enter>) will give
a result that looks like this:
which is NOT correct for the inverse.
4. You now have in the Excel spreadsheet, the A matrix, the B vector, and the inverted A
matrix ( A-1 ):
To calculate the X vector, you now want to multiply the inverted A matrix ( A-1 ) times the
B vector. To do so, the process in similar to the procedure used to calculate the inverse,
except that you will use the Excel matrix function MMULT(). Since the X vector is a 1x3
matrix, mark off the 1x3 cells in Excel that will receive the results of the matrix
multiplication:
Enter the command to compute the multiplication:
where the first range of cells is the cells containing the inverted A matrix ( A-1 ) and the
second range of cells is the cells containing the B vector, enter the function by pressing
<Ctrl><Shift> and <Enter>, and VOILA!! You will have the solution to the problem. That
is, you will have the X vector which contains the values of the unknown x 's of the
problem. Putting labels on the cells in Excel, your solution will look something like this:
5. We can check the solution to this example problem by substituting the values of the
unknowns into the original equations:
x1
3 x1

 2 x2
2 x1
For
x1
x1

3 x1
2 x1
 4
x2
 5 x3
 10

 5
x3
 4.6, x 2

x2
 2 x2
 8.6, x 3
 4.6 
  4.2 :

 8.6 
 4
 5 x3
 3  4.6   2  8.6   5  4.2   10

 2  4.6 
x3
The solution is confirmed!
http://www.sonshinecs.com/mathsolutions/
rae 1/5/2011

 4.2 
 5
Download