Excel Demas
Excel Demas
Busch, 2004
2.
3.
4.
Assignments
1.
2.
3.
R. D. Busch, 2004
an1 an 2
L
L
L
L
a14
a2 n
M
ann
where aij is an element of A , i is the row number, and j is the column number. A
matrix may have any number of rows (R) or columns (C) and is said to be of
order r x c (read as "order R by C"). A vector is a single row or a single column:
v1
r v2
V
M
vn
r
V v1 v2 L vn
These are also known as row vectors, or column vectors, respectively, and are usually
denoted by capital letters and a short overhead arrow. The column vector is an n x 1
matrix while the row vector is a 1 x n matrix. Note that matrices can be denoted by either
parentheses or square brackets.
R. D. Busch, 2004
1 0 0
I 0 1 0
0 0 1
or
0
I M
0
0
0
1
M
0
0
L
L
O
L
L
0
0
M
1
0
0
1
The identity matrix is a special diagonal matrix where the diagonal elements are one, but other
values are possible in diagonal matrices too. A matrix of the form kI is called a scalar matrix.
Multiplication by a scalar matrix yields the same result as multiplication by a scalar: kIA = kA.
The transpose of a matrix A, denoted by A or AT, is the matrix obtained by interchanging the
rows and columns of A.
3 1
3 1 2
T
A
then A 1 4
1
4
0
2 0
Note that transposing a matrix can change its order. In the example above, A is a 2x3 matrix
while AT is a 3x2 matrix. The definition of a transpose determines that the original matrix can be
recovered by transposing the transpose, i.e., the transpose operation is reflexive: (AT)T = A.
Matrix Multiplication
The multiplication properties of matrices underlie their greatest value for engineering
applications. A matrix may be multiplied by a scalar, or a vector, or by another matrix. For scalar
multiplication, we have an element-by-element product:
a11 a12
a
a22
kA k 21
M M
am1 am 2
L
L
L
L
a14
a2 n
M
amn
ka11 ka12
ka21 ka22
M
M
kam1 kam 2
L
L
L
L
ka 14
ka 2 n
M
ka mn
R. D. Busch, 2004
The basic rule is that "adjacent subscripts" must be equal for the matrices to be compatible for
multiplication. It is a simple matter, then, to determine the order of the matrix resulting from a
series of multiplications:
For a matrix A, of order n x m , a product with matrix B will exist under three circumstances:
1. AB if B has m rows,
2. BA if B has n columns,
3. both AB and BA exist if B is m x n
Note also that the matrix AB is said to be matrix A post-multiplied by B, or as A multiplied on
the right by B . Similarly, BA is A pre-multiplied by B , or A multiplied on the left by B. Because
matrices can be multiplied by other matrices, scalars, or vectors, it is useful to remember the
following four results:
a. A row vector post-multiplied by a column vector results in a scalar;
b. A column vector post-multiplied by a row vector results in a matrix;
c. A matrix post-multiplied by a column vector yields a column vector, and;
d. A row vector post-multiplied by a matrix becomes a row vector.
Now, let us look at an example of a matrix multiplication: First, the general definition of an
element of the resultant matrix C is:
a11b11 a12b21
a21b11 a22b21
a11b12 a12b22
a21b12 a22b22
R. D. Busch, 2004
2 1 1
2 3
C A * B 1*1 0* 2 1
1*0 0*1 0
1*1 0*1 1
2*1 3* 2 8
2*0 3*1 3
2*1 3*1 5
1 1 2
C 1 0 1
8 3 5
This example is relatively simple so you can follow the process. However, many applications
have much larger matrices requiring significantly more calculations so using a tool like EXCEL
makes the process easier, quicker, and more accurate.
Matrix Operations in Excel
Excel can do matrix operations very efficiently, either directly, or through the use of
matrix functions. Microsoft prefers to use the term "Array" to "Matrix", so most references in
their manuals and help system can be found under the term array. Key to understanding the use
of matrix operations in Excel is the concept of the Matrix (Array) formula. Such a formula uses
matrix operations and returns a result that can be a matrix, a vector, or a scalar, depending on the
computations involved. Whatever the result may be, an area on the spreadsheet of precisely
the correct size must be selected before the formula is typed in (otherwise you will either
lose some of the answer or get added and possibly confusing information).
Named Ranges
To do operations with arrays, Excel requires that the array be identified. The best
way of identifying an array is to name it similar to the way single cells are named. To do
this, highlight the cells to be included in the range and then go to the name cell and type
in the name. For example if we want to create a matrix that is 3 x 2 (e.g., 3 rows by 2
columns) and is located in cells B3:C5. First highlight all the cells in the matrix as shown
in the figure below, and then go to the name cell and type in matA and then press Enter.
The sheet should look like that below. Once you have named an array, you can enter any
values desired in the cells or change values. We are going to use this matrix and another
to follow the matrix multiplication example above. So, we need to enter the values for
matrix A into the cells. After doing this, the sheet should look like the second one on the
next page.
R. D. Busch, 2004
Now we want to repeat the process for matrix B, which is 2 x 3 (e.g., 2 rows by 3
columns) and is located in cells B7:D8. So first highlight the desired cells and then name
them matB. Then fill in the values as shown in the figure below.
R. D. Busch, 2004
Once you have named a range, you may use it in any formula that allows for a
range as an argument.
Matrix Multiplication
Now that we have our two matrices, we can multiply them together and check our answer
from above. To multiply two matrices, use the MMULT function. Remember, to do matrix
multiplication, the two matrices must be compatible such that the number of columns for the
matrix on the left is equal to the number of rows of the matrix on the right. For our example, we
want to multiply A*B, so A having two columns and B having two rows means this operation can
be perfomed. To compute the product of A*B, use the formula:
= MMULT(matA,matB)
However, there are two caveats when doing array operations. First you must select a
results area that is the correct size for the operation being performed. In this case, we are
multiplying A and B, which should create a 3 x 3 matrix C. So before typing the formula, we
need to highlight 3 rows and 3 columns that will contain matrix C. So lets put matrix C in cells
E4:G6, and name it matC. Note that naming the array is unnecessary unless we want to refer to
it in further operations. After doing this, the sheet should look like the following:
R. D. Busch, 2004
Now, we will type the formula in the formula bar as MMULT(matA,matB) , and the
sheet should look like this.
Now, it is time for the second caveat. Instead of simply pressing Enter when you have
completed typing the formula, you need to use CTRL, SHIFT, and ENTER all pressed together.
We will represent this as Ctrl-Shift-Enter. If you dont do this you will only get a part of
R. D. Busch, 2004
So as you can see Excel got the same answer as we did above. Now what happens if we
multiply matrix B by matrix A. This time we will get a 2 x 2 matrix that we will call D. So
highlight cells E10:F11 and name them matD. Then type = MMULT (matB,matA) as the
formula and then press Ctrl-Shift-Enter. This should produce the following:
R. D. Busch, 2004
R. D. Busch, 2004
For matrices larger than 3x3, the expansion by minors process to calculate determinants
is very tedious. However, Excel will calculate the determinant of a matrix quite quickly. For a
square matrix, enter the values and assign a name to the array in excel. Then in a single cell,
enter the array formula, = mdeterm(arrayname) and Ctrl-Shift-Enter. This will
place the calculated determinant in the cell. If the determinant is non-zero, then you can calculate
the inverse of the matrix. If the determinant is zero, then the inverse is undefined, and any
subsequent operations involving the inverse will also be undefined.
Combining Matrix Operations
In Excel, you may combine matrix operations in a single formula. Remember, however,
that everything must conform, that the output range should be the correct size for the final result,
and that you must press CTRL-SHIFT-ENTER to enter the formula in the output range. As in all
complex formulas, it never hurts to include sufficient parentheses to explicitly identify each
mathematical operation.
Linear Simultaneous Equations
In many engineering applications, there will be multiple unknowns and a set of equations
relating the unknowns. For example, a problem that arises in circuits is the analysis of currents in
a Wheatstone bridge containing 5 resistors and a voltage source.
R. D. Busch, 2004
(R2 + R4)
=
-R2
-R4
-R2
-R4
(R1+R2+R5)
-R5
curr=
-R5
(R3+R4+R5)
i1
i2
i3
const=
E
0
0
So using matrix operations, we can solve for the currents as curr = R-1 * const. Or using Excel,
the current vector is 3x1 and will be computed from the formula; =MMULT(MINVERSE(R),
const). Lets say, E = 10 volts, R1 = 2 ohms, R2 = 6 ohms, R3 = 1 ohm, R4 = 3 ohms, and R5
= 3 ohms (balanced condition as 6*1 = 2*3), then we will enter the following into Excel for
matrix R and the const vector.
R
9
-6
-3
-6
11
-3
-3
-3
7
const=
10
0
0
After naming the arrays and entering the array formula, Excel indicates that i1 = 2.22, i2 = 0.98,
and i3 = 1.37. The calculation should look like the sheet below.
R. D. Busch, 2004
an1 an 2
x1
x2
a14
a2 n
M
ann
L
L
L
L
c1
c2
x
n
const
c
n
Then the unknowns in the x vector are calculated by entering the formula
=mmult(minverse(matA),const). Again, there is the caveat, that the determinant of A
must exist or the system of simultaneous equations will not uniquely define the unknowns. This
can also be stated as the equations are not linearly independent.
R. D. Busch, 2004
0
2
0
0
1
0
0
2
1
0
1
4
0
2
1
1
1
2
2.
3.
Calculate the following products: A*B, B*A, A*C, A*B*C, B*A*C, and A*I
(remember I is used to denote the Identity matrix, of the same order as A in this case).
1
A 0
1
4.
0
1
0
1
0
3
2
1
0
1
1
1
3 x1 2 x 2 2 x3 6
3 x1
x 2 x3 2
1
C 0
1
R. D. Busch, 2004
(Taken From Applied Numerical Methods by Carnahan, Luther, and Wilkes) When a pure
sample of gas is bombarded by low energy electrons in a mass spectrometer, the
galvanometer shows peak heights that correspond to individual m/e (mass-to-charge)
ratios for the resulting mixture of ions. For the i th peak produced by a pure sample j, one
can then assign a sensitivity, sij, (peak height per micron Hg sample pressure). These
coefficients are unique for each type of gas. A distribution of peak heights may also be
obtained for an n-component gas mixture that is to be analyzed for partial pressures, p1,
p2, , pn of each of its constituents. The height, h i, of a certain peak is a linear
combination of the products of the individual sensitivities and partial pressures.
n
hi s ij * p j
j 1
The sensitivities in the table below are related to the analysis of a hydrocarbon gas
mixture.
Peak
index
M/e
ratio
1
Hydroge
n
2
3
Methane Ethylen
e
4
Ethane
5
Propylene
6
Propane
7
n-Pentane
1
2
3
4
5
6
7
2
16
26
30
40
44
72
16.87
0.0
0.0
0.0
0.0
0.0
0.0
0.165
27.7
0.0
0.0
0.0
0.0
0.0
0.317
0.062
13.05
11.28
0.0
0.0
0.0
0.234
0.073
4.42
0.0
9.85
0.299
0.0
0.182
0.131
6.001
1.110
1.684
15.98
0.0
0.110
0.120
3.043
0.371
2.108
2.107
4.67
0.2019
0.862
22.35
0.0
0.0
0.0
0.0
A particular gas sample produced the following peak heights: h1 = 17.1, h2 = 65.1, h3 =
186.0, h4 = 82.7, h5 = 84.2, h6 = 63.7, h7 = 119.7. The measured total pressure of the
mixture was 39.9 microns Hg, which can be compared with the sum of the computed partial
pressures. Compute the partial pressures of each constituent.
Find all solutions of each set of equations
2.
5x + y + z = 2
x - 2y z = -2
2x + y + 3z = 6
3.
x - 7y + z = 3
2x + 5y - 9z = 2
R. D. Busch, 2004
y - 25z = 13
Suppose a parabola has its axis parallel to the x-axis and passes through the points
(1,-1), (2,0) and (2,2). The parabola then has an equation of the type
(y-k)2 = 4p(x-h)
or y2 + Ay + Bx + C = 0
If you substitute the coordinates of the three given points in the latter equation, you
should create a set of three equations for the 3 unknowns: A, B, and C. Solve these for
A, B, and C to determine the equation of the parabola.
5.
For matrix A and B given below, calculate A*B and B*A. For each product, give the
order of the resulting matrix and the value in each cell.
1
1
A
1
1
1
0
1
1
0
1
0
1
1
2
1