Week 12th Arrays and Matrix in EXCEL
Week 12th Arrays and Matrix in EXCEL
engineering calculations. Sets of simultaneous linear equations are typically solved using matrix methods, and these occur in numerous areas, including linear programming problems, and in solving differential equations.
Matrix manipulations area natural for Excel worksheets; the worksheet grid provides a natural home for the columns and rows of a matrix. Ail standard spreadsheet programs provide the standard matrix math operations. Excel goes a step further and allows many matrix operations to be performed by using array junctions rather than menu commands. This makes the matrix operations "live"; they will automatically be recalculated if any of the data is changed.
5.2 MATR!CES, VECTORS, AND ARRAYS
Excel uses the term ({I'ray to refer to a collection of values organized in rows and columns that should be kept together. For example, when arrays me used in formulas any mathematical operation performed on any element of the array is performed on each element of the array. Also, Excel will not alJow you to delete a portion of an array; the entire array must be deleted, or the array must be converted to values using Ribbon options Home/Clipboard/Paste (menuj/Paste Values [Exec I 2003: Edit/Paste Special/Values]. Functions designed to operate on or return arrays are called array junctions.
Standard mathematics nomenclature calls a collection of related values organized in rows and columns a matrix. A matrix with a single row or column is' called a vector. In Excel, both would be considered arrays.
Defining and Naming Arrays
You define an array in Excel simply by filling a range of cells with the contents of the array, For example, the 3 X 2 matrix
[1 3]
A = 7 2
8 11
can be entered into a 3 x 2 range of cells as shown in Figure 5.1.
Figure 5.1
Matrix A in cells B4:C6.
1'1 dl sic 01 t r<'
I
yb
212 Chapter 5 Matrix Operations in Excel
Naming a range of cells allows you to use the name (e.g., A) in place of the ceil range (e.g., B4:C6) in array formulas. Excel's matrix math functions do not require named arrays, but naming the cell ranges that contain the arrays is commonly done. Using named arrays not only expedites entering array formulas, it also makes your worksheets easier to read and understand.
To give a name to the range of cells that hold an array:
1. Select the cells containing the array.
Enter the desired name in the Name box at the left side of the Formula Bar.
Be me
5.4
Till
ma
USe
the 138) BL
mat
Figure 5.2
Cell range B4:C6 has been named "A."
J\1ai Ii tl
Alternatively, a selected range can be assigned a name by using Ribbon options Formulas/Defined Names/Define Name [Excel 2003: Insert/N arne/Define]
5.3 HOW EXCEL HANDLES MATRIX MATH
Excel provides mechanisms for performing each of the standard matrix operations, but they a~'e accessed in differing ways:
c Addition and scalar multiplication are handled through either basic cell arithmetic or array math operations.
e Matrix transposition, multiplication, and inversion are handled by array functions.
The various worksheet programs handle matrix operations, such as transposition, multiplication, and inversion in different ways. Some programs treat a matrix as a range of values, and matrix operations (from menus, not functions) produce a new range of values. Excel handles standard matrix operations using array functiolls.
lew ms.
Figure 5.3
Entering the matrices to be added.
Section 5.4 Basic Matrix Operations 213
11Jere arc pros and cons to each approach. Excel's array functions require mare ffort on the user's part to perform matrix transposition, multiplication, and inver:ion, but, by using array functions, Excel can recalculate the resulting matrices if any
f the input data change. When worksheet programs do not use functions for matrix ~ransposition, multiplication, and inversion, they cannot automatically recalculate matrix results when your worksheet changes.
There are a couple of common features of engineering work that suggest that the automatic recalculation provided by array functions is important:
1. Engineers frequently have to start preparing designs with estimates or "gllesstimates" (educated guesses) of important parameters. When better values become available, the estimates are replaced with the values. Automatic recalculation allows you to immediately see the impact of the new value on the proposed design.
2. Engineers routinely develop designs that have adjustable parameters, at least in the early stages. Changing the parameters values to evaluate the impact on the design is common, and automatic recalculation is essential.
Because array functions support automatic recalculation, array functions will get most of the attention in this chapter.
The two matrices to be added must be the same size. Begin by entering the two matrices to be added. Figure 5.3 shows two small matrices, [A J and [BJ, that will be to demonstrate matrix addition.
The matrices are added element by element. For example, the top-left cell of the resultant matrix will hold the formula required to add 1 + 4 (cell B4 plus cell BS). The formula would be written as =B4 + B8. When this formula is placed in cell B12, the result is displayed. (See Figure 5.4.)
If the formula in cell B12 is now copied to cells B12:C14,ExceJ will add the [AJ matrix and the [B] matrix clement by element. TIle result is shown in Figure 55.
Matrix Addition Using Array Math
If the cell ranges holding matrices (A] and [B] are named, then the array names can be used to perform the addition. In this example, the name "A" was applied to cell range B4:C6, and cells B8:CIO were named "B."
ms,
ith-
)ns.
0$1-
214 Chapter 5 Matrix Operations in Excel
figure 5.4 Beginning the addition process.
sh
III (h
Figure 5.5
Adding matrices A and B.
In Excel, any time array math. is used, the size of the resulting array must be indicated before the entering of the array formula. The result of adding matrices [A] and [B] will be a 3 X 2 matrix, so a 3 X 2 region of cells (B16:C18) is selected, as shown in Figure 5.6.
Figure 5.6
Indicate the size of the result before entering an array
Section 5.4 Bosic Matrix Operotions 215
Then ·the formul a '" 2\ + B is entered in the top-left cell of the selected range, as shown in Figure 5.7. Notice that when the named arrays were entered in the forExcel put a box around the named arrays. 111is allows you to quickly see that the correct matrices are being added.
J
... <-1 -,-- __ 8_· __ --!
1 7
~_" •• c c ~. __ , •
Whenarray names
.. are used Tn "formuias, ·th·earr·ays·are····· indicated'with I cOIOred·bordets.
Figure 5.7
Enter the array formula in one cell of the selected array.
216 Chapter 5 Matrix Operations in Excel
IMPORTANT! Excel requires a special character sequence when entering array formulas: [Cirl-Shift-Enter], not just the [Enter] key. The [Ctrl-Shift-Enter] key combination tells Excel to fill the entire array (i.e., the selected region) with the formula, not just one cell. After the pressing of [Ctrl-Shift-Enter], the worksheet looks like Figure 5.S.
Each cell in the new array (B16:C18) contains the same formula, {=.~ + B} . The braces { } indicate that array math was used and that the result is an array. This means that the six cells in B16:C18 are considered a colleciion, and individual elements of the new array cannot be edited or deleted. However, if either matrix [A] or matrix [B] is changed, the new array will automatically be updated.
Note: Named arrays are not required for array math in Excel; the same result could have been obtained by selecting the B16:C18 range, then typing in the array formula =B4 :C6 + 88 :Cl0 and pressing [Ctrl-Shift-Enter]. The array formula {= 84 :C6 + B8 :Cl0} would have been entered into every cell of the new array, and matrices [A] and [B] would have been added.
lilt !ill las
fjg,:,r~ S.B ... ·.···· .; ··• ... ·<Theresult,using
to add two matrices.
!l1U
Sea
5.4.2 Multiplying a Matrix by a Scalar
Begin by entering the scalar (constant value) and the matrix that it is to multiply, as shown in Figure 5.9. It is not necessary to name the cell containing the scalar, but in this example cell B3 has been named "3," for scalar.
Multiplying a matrix by a scalar simply requires you to multiply each element of the matrix by the scalar. Using cell math, you first multiple the scalar by one element of the matrix, usually the top-left element as shown in Figure 5.10.
By placing the formula =S*B5 in cell B9, you instruct Excel to multiply the contents of the cell named "S" (cell B3, the scalar) and the contents of cell B5 (the top-left element of the matrix). Cell names in formulas act as absolute addresses,so
cell nan
euti In e
5.4 ..
Iii 0
cqu.
Figure 5.9
Preparing to multiple matrix [A] by a scalar.
Section 5.4 Basic Matrix Operalions 217
Figure 5.10
Multiplying the scalar by the First element aF the matrix.
iult the 'or-
the formula "'5*B5 is equivalent to "'$B$3*B5.111e absolute address on the scalar is in preparation for copying the formula to other cells. When copied, the new formulas will continue to reference the scalar in cell B3.
Copying the formula in cell B9 to the range B9:Cll completes the process of multiplying the matrix [A] by the scalar, 10.1ne results are shown in Figure 5.11.
. , as tin
Scalar Mu/tipJke1ion Using Array Math
The same result can be obtained using array math and a named array. If the cells holding the [A] matrix (B5:B7 in this example) are named "A," then the array name can be used to perform the scalar multiplication.
First, the size of the result matrix is indicated by selecting a 3 X 2 range of cells (B13:ClS), and the array formula ",S*A, is entered in the top-left cell of the new array, as shown in Figure 5.12 .
The formula is concluded by pressing [Ctrl-Shift-Enter] to tell Excel to fill the entire selected region with the array formula. Excel places the array formula (=s*.rq in each cell in the result array, as illustrated in Figure 5.13.
ent ~le-
the
5.4.3 Multiplying Two Matrices
In order to multiply two matrices, the number of columns in the first matrix must equal the number of rows in the second matrix.
Again, begin by entering the two matrices to be multiplied. (See Figure 5.14.)
,so
Figure 5.11
Copying the formula in cell B9 to cells B9:Cll to complete the multiplication.
218 Chapter 5 Matrix Operations in Exce!
Figure 5.12
Starting the scalar multiplication using array math.
rna. ent. nail
(Fig
Figure 5.13
The completed scalar multiplication using orroy math.
CO III [Or lion 1312
~.
Ii. ~
.-,~~~~--
figure 5.14
Preparing to multiply two matrices.
Section 5.4 Basic Malrix Operations 219
pie the product matrix will be 3 rows by 1 column.
Note: It is best to indicate the correct number of cells, bu t if you indicate too many cells, the multiplication will still work, but extra cells will display the #NI A error code. If you indicate too few cellspart Of the product matrix will not be displayed.
Once you have indicated where the new matrix is to go, begin entering the matrix multiplication array function, LJ'.l.NULT(first matrix, second matrix} . After entering the equal sign, function name, and the opening parenthesis, enter the array names separated by a comma as illustrated in Figure 5.16.
Alternatively, you can use the mouse to indicate the cell ranges for each array (Figure 5.17), but the array names will not be used with this approach.
Whether you use array names (Figure 5.16) or cell ranges (Figure 5.17), you complete the matrix multiplication formula in the same manner, by pressing [Ctrl-Shift-Enter], not just the [Enter] key. The MMULT() function is an array function, <mel the [Ctrl-Shift-Enter] is used to enter the function into all of the cells from B12 to B14. The result (using array names) is shown in Figure S.lS.
Note: Pressing [Enter] instead of [Ctrl-Shift-Enter] would enter the formula 0111y in eel] B12, and only one clement of the product matrix would be displayed.
220 Chapter 5 Matrix Operations in Excel
,',
.l.
11
Figure 5.15
Indicating the size of the
1.G
Figure 5.16
Indicating matrices to be multiplied by name,
lS
Note: Excel places the formulas for multiplying the matrices in the result cells, not just the final values, Because of this, any changes in the first two matrices will automatically cause the product matrix to be updated,
3.
Process Summary: "\J1atrix Multiplicatioll
5.
L Enter the matrices to be multiplied; the inside dimensions must be the same.
2. Give the matrices names by selecting the matrix cells and using the Name boX at the left side of the Formula bar (optional),
'Us, ces
Figure 5.18
The result o~ multiplying two motrices.
Sedion 5.4 Basic Matrix Operations 221
ne. lOX
3. Determine the size of the product matrix from the outside dimensions of the matrices being multiplied.
4. Select the cells that will hold the product matrix.
5. Enter the matrix multiplication formula =t1l;,rill,T (first~matrix, second_matrix) in one cell of the destination cell range. Indicate the first and second matrices either by name or using cell addresses
6. Complete the multiplication by pressing [Ctrl-Shift-Enter] to cause Excel to place the forfiiiila in each cell of the product matrix.
u T
222 Chapler 5 Malrix Operations in Excel
Practice!
Can the following matrices be multiplied, and, 'if so, what size will the resulting matrices be?
(S.l)
[ANSWERS: yes, 3 X 2; no; yes, 1 X 3] I
---_J
7 S
Section 5.4 Bosic Matrix Operations 223
5.4.4 Transposing a Matrix
Any matrix can be transposed. To transpose a matrix, simply interchange the rows and columns. You can transpose a matrix in two ways: as values or by using the array function TRANSPOSE ( ). Using values is simpler, but the result will not be automatically recalculated if the input data change. Both methods are described
here.
Using PASTE SPECIAL fa Transp ose as ValuES
'The process in Excel can be summarized as follows:
1. Enter the original matrix.
2. Begin the transposition process by selecting the cells containing the matrix and copying the matrix to the Windows clipboard using Ribbon options Home/ClipboardJCopy [Excel 2003: Edit/Copy).
3. Indicate the cell that will contain the top-left corner of the result matrix.
4. Open the Paste Special dialog using Ribbon options Home/Paste (menu)/ Paste Special ... [Excel 2003: Edit/Paste Special ... ].
5. Select Values in the Paste section, and check the Transpose check box near the bottom of the dialog.
Using a A10trix Function ro Transpose a Ma?rix
Using the TRANSPOSE () array function, the process is as follows:
1. Enter the original matrix (Figure S.20).
2. Indicate where the result should be placed, showing the exact size of the transposed matrix. (See Figure S.21.)
3. Enter the =TRANSPOSE (matrix) array function (Figure 5.22). The matrix to be transposed can be indicated by name, or cell range.
4. Complete the transpose operation by pressing [Ctrl-Shift-Enter] to transpose the matrix and place the formula in every cell in the result matrix. (See Figure 5.23).
Figure 5.20 Preparing to transpose matrix A.
224 chapter 5 Matrix Operation> in Excel
figure 5.21
Indicating where the transposed matrix wil! be placed.
01 po (Tf
Figure 5.22
Entering the TRANSPOSE () formula.
figure 5.23 Completing the transpose operation.
As
5.4.(
The
Usee the, zero onlv
Section 5.4 Basic Matrix Operations 225
Practice!
Transpose the following matrices: [6 1 4]
1.2]
6.1
2.3
u 0 ~]
1 (5.2)
0
[6][ 1 .., 2\l[~ 0 n
.J
ANSWERS: 1. ') 6.1 1
4 . 1._ 0 Only square matrices (the number of rows is equal to the number of columns) can possibly be inverted, and not even all square matrices can actually be inverted. (They must be nonsingular to be inverted.)
The procedure to invert a nonsingular, square matrix in Excel, using the NIN"VERSE () array function, is as follows:
1. Enter the matrix to be inverted, and name it if desired.
2. Indicate where the inverted matrix should be placed and the correct size (same size as original matrix).
3. Enter the MINVERSE (rna trix) array function. TIle matrix to be inverted can be indicated by name or cell range.
4. Press [Ctrl-Shift-Enter] to enter the array function in all the cells making up the result matrix.
As an example oft his procedure, we will in vert th e [l] matrix, ] = [~ ~ : J After the first three steps, the worksheet looks like Figure 5.24.
We complete the inversion process by pressing [Ctrl-Shift-Enter] to enter the array formula into every cell in the result matrix. The result is shown in Figure 5.25.
5.4.6 Matrix Determinant
The determinant of a matrix is a single value, calculated from a matrix, that is often used in solving systems of equations. One of the most straightforward ways to use the determinant is to see whether a matrix can be inverted. If the determinant is zero, the matrix is singular and cannot be inverted. You can calculate a determinant only for square matrices.
Note: Calculating a determinant for a large matrix requires a lot of calculations and can result in round-off errors on digital computers. A very small,
nonzero determinant (e.g., 1 x 10.-14) is probably a round-off error, and the matrix most likely cannot be inverted,
Excel's MDETERt'1{matrix) array function is used to compute determinant values. In the previous section, the [J] matrix was inverted, so it must have had a nonzero determinant. We can use the l.'IDETERN () function to verify that, as illustrated in Figure 5.26.
If the matrix is singular (and so cannot be inverted), the determinant will be zero, In the [K] matrix shown in Figure 5.27, the secone! row is the same as the first row. Whenever a matrix contains two identical rows the matrix cannot be inverted, and the determinant will be zero.
A matrix is singular (and cannot be inverted) if
e any row (or column) contains all zeros;
<I any two rows (or columns) arc identical;
226 Chapter 5 Matrix Operations in Excel
figure 5.24
Inverting the [J] matrix, just before completing the array formula,
Figure 5.25
The inverted matrix.
6
7
8
G an'
cell!
Wher linea! equal
5.5 ~
One c brei: works
L
2.
3+ r\
The re
Figure 5.26
Calcu!ating the determinant of [JJ.
Section 5.5 Solving Systems of linear Equalions 227
figure 5.27
Calculating the determinant o] singular matrix [KJ.
• any row (or column) is equal to a linear combination of other rows (or
columns).
When two or more rows are multiplied by constants and then added, the result is a linear combination of the rows. When a linear combination of two or more rows is equal to another row in the matrix, the matrix is singular.
.al:1 a
5.5 SOLVING SYSTEMS OF LINEAR EQUATIONS
us-
be irst ed,
One of the most common uses of matrix operations is to solve systems of linear algebraic equations. 111e process of solving simultaneous equations by using matrices works as follows:
1. Write the equations in matrix form (coefficient matrix multiplying an unknown vector, equal to 8 right-hand-side vector).
2. Invert the coefficient matrix.
3. Multiply both sides of the equation by the inverted coefficient matrix.
The result of step 3 is a solution matrix containing the answers to the problem.
3Xl + 2X2 + 4.1'3 "" 5, 2Xl + 5X2 + 3x3 "" 17, 7Xl + 2X2 + 2X3 ce 11.
(5.3)
228 Chapter 5 Matrix Operations in Excel
In order for inverting the coefficient matrix to be possible, it must be nonsin. gular. In terms of solving simultaneous equations, this means that you will be able to invert the coefficient matrix only if there is a solution to the set of equations. If there is no solution, the coefficient matrix will be singular.
Consider the following three equations in three unknowns:
I" ]
Xl
[xl zzz l~: .
Step 1. Write the Equations in Matrix Form. SteF
The unknowns are xl, .1:2, and X3, which can be written as the vector of unknowns, [r] u~~
The coefficients multiplying the various x's can be collected in a coefficient matrix [C]
7 2
Practice!
Try multiplying [C] times [x] (symbolically) to see that you do indeed gel back the left side of the preceding equation.
f3Xl + 2X2 + 4X3]
ANSWER: [C][x] = 2.\1 -t- 5X2 + 3X3 . i
'- 7 Xl -[- 2X2 -1- 2x3 I
~~~---------~
Step
The constants on the right side of the equations can be \VI itten as a righl-hand· side vector [r 1:
i5l
I '"1 !
lr J = 1 17 .
LllJ
[C][X] = [1'].
The three equations in three unknowns can now be written as
In a worksheet, the arrays can be entered as shown in Figure 5.28. In Excel, names C and r are reserved for "column" and "row" so the matrices have been named Coeff and rhs in the worksheet shown in Figure 5.28. So, for this exam· ple, the matrix equation is written as
[Coeffj].»] = [rhs].
Section 5.5 Solving Systems of linear Equations 229
Figure 5.28
Entering the coefficient matrix and right-hanel-side vector in Excel.
figure 5.29
Inverting the coellicient matrix .
. Step 3. Multiply Both Sides of the Equation by the Inverted [Coerf1 Marrix, [Coeffin'.,J. [Cocffinv][ Coeff][ x] = [Coeffinv ][rhs]
[J][x] = [Coeffiov][rhs]
I=l = [Coeffinv](rhsJ. (5.4)
What's happening here is the following:
.. Multiplying the inverted coefficient matrix [Coeffillv] and the original [Coeff] matrix returns an identity matrix, called [I]. (Try itl)
.. Multiplying the [x] vector by an identity matrix [I] returns the [x] vector unchanged.
~ So multiplying the inverted coefficient matrix [Coeffinv] and the [rhs] vector returns the [x] values, which is the solution.
The solution of the original three equations in three unknowns is shown in
Figure 5.30. So the answers to the original three equations are
Xl = 0.846,
X2 """ 3.846,
X3 "" ~1.31.
111L
230 chapter 5 Matrix Opera lions in Excel
In I
Figure 5.30
Solving for the unknown vector, [xl.
We COil
Section 5.5 Solving Systems of lin€OI' Equations 231
E - V2 - VI = 0, E - V3 - VI = O.
In terms of current and resistance, these are
E - i2R2 - ijR1 = 0, E - i3R3 - i1R1 = O.
c ~ [~j -1 -1 J [0 J
R2 ~3 .. r =:~.
RI 0
C ~ [3~ -1 -IJ [OJ ..
40 ~O ... r 'C .:i ..
30 0 In Excel, the coefficient matrix andright-hand-side vector shown in Figure 5.32.
A quick check with Excel's !:·IiJETER.'VJ () i a solution is possible.
·----,-----~·--O-- .. ---,----------,.--'-----
· .... A ! B DE·
•• ". ~.'. c. ". _ •• " •••
.·i· .
__ .~" .. iMuimoop Circuits;
'2
sr -.-"fj 'l - 1 -1 [rhs] o
~ ,_\..,1.::! _,_
311 40 Cr 12..
30 n SCI 1.2 The coefficient matrix is inverted by using the MIJ:..lIiERSE () . shown in Figure 5.34.
232 Choprer 5 Matrix Opera lions in Excel
Section 5.5 Solving Systems of Linear Equations 233
234 chapter 5 Matrix Operations in Excel
i ·····The GridgeCol1fai6~t\~Oknow~11:csistmic~s,RJ til~d Rz, ~nil~ri<ldjl~stable resis_ .•..
...tancc(i.e., ~. potelltiometei·) ,f:.4· .. In,}lSe,th~setting oli Uicricitenti()ineteris adjusted' ". llnti1lJoirltsa aridb ate Zltthesaluc:.vqltage:Thcntl1e knOwn tesis.t~U1ceSCal1.be used -:
.• ··tocalcu.late an unknown resistance, shown as R.3 in Figure5.30. . .
. . 'Todevelop theequationsforfindingciirrents il through i3,I1ote that Rl and.
the.potcntiometer,R4, are connected at pointcand the circuit has been adjusted to' have the same potential atpointscando.Therefore the voltagedropsaCi"oss R, and '.
Rr must be equal: . . . . .' ". '.' .
or, i
i.
f-. L.
~i~~;_
Section 5.5 Solving Systems of Linear Equofions 235
to lK pe
2:36 Chapte!" 5 Matrix Operations in Exce!
as
wh, TJ 1
rc~ I
i
Or
any!
Section 5.5 Solving Systems of Linear Equations 237
l000C
40.cm
50 em
The par can
duce the algebraic equation
o = [Ti.;.lJ - 2T.·,j + li-1.j] + [_T_:i'J_'+_l--,,--~_:_ _ _:_..,....,..
(.c.xf .
100"C
c
i,j - l
O°C 0 13
i-l,ji,j
.Q: .....
25'C
!
-r-: ... f:
4~,j = [Ti+1,j + 1;"'J,j] + Fi,j+l +1i,i-lJ
23B Chapter 5 MCltrlx Operotions in Excel
.. ' ..
Tohelpsee bow this is done, let's assign each interior point a letter designation and showthe fourpointssurrounding poinrAwithacirclefasshown in Figure 5.'13 '.
Applying the general.equation atpointA'(see Figute5.43) yields .
47'4= 0+100 Ts+h
. . " ,
Then, we move the circle to point :I3,assbmvn )nFigure 5044.
ffigure5.43
Assigning letter names to grid pointsend identifying point ks neighboring points.
~igure 5.44 . The circle used to identify neighboring points has been moved to point B.
··25"C
. Applying the general equation at pointB'yields
4 Ts = TA + 100 + t; -+h·
By continuing to apply the general equation at each interior point (points A through L), we generate 12 equations, one for each interior point:
4 TA = 0 + 100 + TE + TE
4T13 = TA + 100 +Tc +- TF
4 Tc= TB + 100 + TD + Te
4 TD= t; + 100+ 100 -+ Tf{
4T£ =0 + 7~\ +- TF+TJ
4TF=h+Ts Tc+Tj 4Te = TF +Tc 4- TI-J + Tf( 4T1-10::. To -+- TD 100 +r; 4T{ =0 + IE + T, + 25
AT, = T, + TF+ TK +25 4 Tf( = IJ + Ie +TL +.25
4Tt_= TK +TH+ 100 25.
In matrix form, these equations can be written as [Coeff][T]= [rh5]
where
In
to
12
21
0
0
1
-4
0
0
0
1
0
0
0 0
0 0 0 0 Section 5.5 Solving Systems of Linear Equations 239
1
J o o 1 () () 1 o 0 o
The coefficient and right-hand-side into Excel, as shown in Figure 5.45.
Now the coefficient matrix can be inverted and UH:"H.Hl).ll
! ·0.30 ·O.W -0.04 -C.01 -0.10 ·G.07 -0.03 ·0.01 -1.1.03 -0.03 -0.02 -0.0t 1·0.10 -0.34 -0.11 -0.04 -0.07 ·C.13 ·O.CS ·0.03 ·0.03 -0.05 -0.04 ·0.02 1-0.04 -0.11 -034 .1).10 ·(1.0;; ·C.08 ·0.13 ·0.07 ·0.02 ·0.04. -0.05 ·0.03 ~ -C.Dl "O.G~ -o.ic DO.3C -D.C! ·{}:03 -C.07 -C.IO -0.01 -O.C::' -0.03 -0.03 1-0.10 ·1).07 -0.03 -0.01 -0.33 ·0.13 -0.C5 -0,02 ·0.10 -0.07 -0.03 ·0.01
:
i ·0.07 -0.13 ·Cf;S ·0.03 -O.E ·C.39 -0.15 -0.05 -C.07 -0.13 -G.OS -0.83
I .
~ -0,03 TO.03 ~0.13 -C.O: -C.G5 -0.15- -0.39_ -0.13 -0.03 -0.08 -0.13 -0.07
1,0.Ol ·0.03 -0.G7 ·0.10 ·0.02 -C.05 -0,.13 ·033 -0.01 -0.03 -0.07 -0.10 i
i -0.03 -0.03 -0.02 -0.01 -0.10 -O.OT -0.0; -0.01-0.30 -0.10 -0.04 -0.01
,
'1.0.03 -0.05 -0.04 ·(;.01 -G.07 ·0.13 ·0.08 ·0.03 -0.10 ·0.34 -0.11 ·0.04
. -G.02 ·0.04 -0.05 ·0.03 -0.03 ·C,OS ·G.B ·0.07 ·0.04 -0.11 -0.34 ·0.10 1-0.01 ·0.02 -0.03 ·0.03 ·1)01 ·1].03 -0.07 ·G.1D ·0.01 ·0.04· ·0.10 ·0.30
G. : .H, . ~
~o." =1.
. 0.6 "T. 1,4 -:::T~ 0.2 =T D I 31.1 =T~ 150.8:T, 164.7 ~T~
[T] I'C)
..figt,!re5.4~·" .. . . T~ eco leu latedinteri or .... ····temperatur~s.i
240 Chapter 5 Matrix Operotions in Excel
KEY TERMS
matrices matrix
matrix addition matrix inversion matrix multiplication named array nonsingular right-hand-side vector
scalar
scalar multiplication singular
systems of linear algebraic
equations transpose unknown vector vector
array
array functions array math
automatic recalculation coefficient matrix (Ctrl-$hift -En ter] determinant
invert
linear combination
Naming a Matrix
1. Select the cells containing the array.
2. Enter the desired name in the Name box at the left side of the Formula Bar.
Process for Using Array Math in Excel
Enter the array math formula into one cell (typically the top-left one). Press [Ctrl-Shilt-Enter] to enter the array lormula into all selected cells.
Basic Matrix Math Operations
lidding Two Matrices
Rcq uirement: "The matrices to be added must be the same size. Options: Use basic cell arithmetic or array math.
Process: Add elements by element.
j'jIf atrix Multiplication by a Scalar
Requirement: Any matrix can be multiplied by a scalar value. Options: Use basic cell arithmetic or array math.
Process: Multiply each element of the array by the scalar.
fy[u/riplying Two Matrices
Requirement: The number of columns in [he first matrix must equal the number of rows in the second matrix.
Size of result: The size of the product matrix is dele rmined from tbe number of rows in the first matrix and the number of columns in the second matrix.
Process: Multiply across columns and clown rows. CTI1is is handled by the
r'lMULT () Iunction.) To multiply two matrices,
L Enter the matrices to be multiplied.
2. Give the matrices names (optional).
3. Determine the size of the product matrix.
4. Select the cells that will hold the product matrix.
5_ Enter the matrix multiplication formula =l1t<IULT(first __ mat.r i.x, second_ matrix) .
6. Complete the multiplication by pressing [Ctrl-Shilt-Enter].
1/
rei
ill
1ft
So,
Summary 241
hJJ1S/J'O~,fllb a Matrix Using Edit/Paste (does not automatically recalculate) Requirement: Any matrix can be multiplied by a scalar value.
Process: Interchange rows and columns by following these steps:
L Select the array to be transposed, and copy it to the Windows clipboard, using Ribbon options Home/Clipboard/Copy.
2. Indicate the cell that will contain the top-left corner of the result matrix.
3. Open the Paste Special dialog using Ribbon options Home/Paste (menu)/I~aste Special .. ,
4. Select Values in the Paste section, and check the Transpose check box near the bottom of the dialog.
5. Click the [OK] button to close the dialog box and create the transposed matrix.
Transposing a Matrix Using Array Function TRANSPOSEO (automatically recalcuZates)
Requirement: Any matrix can be multiplied by a scalar value. Process: Interchange rows and columns by following these steps:
1. Enter the original matrix.
2. Indicate where the result should be placed, showing the exact size of the
4. Complete the transpose operation by pressing [Ctrl-Shitt-Enter] to transpose the matrix and place the formula in every cell in the result matrix,
Requirement: Only a square, nonsingular matrix can be inverted. (A nonzero determinant indicates a nonsingular matrix.)
Process: Complex; fortunately, it is handled by the MINVERSE () function. To invert a matrix,
1. Enter the matrix to be inverted, and name it (optional).
2. Indicate where the inverted matrix should be placed, and indicate the correct size (the same size as the original matrix).
3, Enter the MINVERSE (matrix) array function. The matrix to be inverted can be indicated by name or cell range,
4. Press [Ctrl-Shift-Enter] to enter the array function in all the cells making up the result matrix.
Matrix Determinant
Requirement: The determinant is calculated only for a square matrix.
Process: Complex; fortunately, it is handled by the MDETERM () function. To calculate the determinant of a matrix,
1. Enter the matrix.
2, Use the formula "'MDETERM (rna trix) to calculate the determinant of the matrix.
Solving Systems of Linear Equations
Requirement: Must be as many equations as unknowns. Process:
1. Write the equations in matrix form (coefficient matrix multiplying an unknown vector, equal to a right-hand-side vector),
(a) c~[i 0 ~}~GJ
7
3
c ~ [~ 2 l~[:l,
(b) 1
5 1 3J 5.
242 Chapter 5 Matrix Operations in Excel
2. Invert the coefficient matrix.
3. Multiply both sides of the equation by the inverted coefficient matrix.
5.1. Simultaneous Equations I Use Excel's I'IDETERN () array function to see whether there is a solution to the simultaneous equations represented by each of the coefficient and right-hand-side matrices shown.
If the solution exists, solve the equations by using matrix methods.
5.2. Simultaneous Equations II Write the following sets of simultaneous equations in matrix form, and check the determinant to see whether there is a solution:
(a) OXl + 7x2 + 1x3 = 3, 3Xl + 6X2 + 3x3 = 8, -3Xl + 8X2 - Ix) = 2. (b) lx1 + 8X2 + 4X3 = 0, -!xl + lx2 + 7X3 :::: 7, 6X1 + 7 x2 - 2X3 = 3.
(c) 6Xl + 5X2 - 1x3 + 6X4 = 0, -2x1 + 2X2 + 2x3 + 2X4 ee 1, lX1 - lx2 + 1X3 - 2X4 = 1, 7 Xl - 3X2 + 8X3 + 4X4 "" 4.
If a solutions exists, solve the equations using matrix methods.
5.3. Simultaneous Equations III Write the following sets of simultaneous equations in matrix form and solve the new equations (if possible):
(a) 3X1 + lX2 + 5x3 :::: 20,
2xl + 3X2 - 1x3 = 5,
-1x! + 4X2 = 7.
(b) 6Xl + 2X2 + 8x3 = 14,
Xl + 3X2 + 4X3 = 5,
5Xl + 6X2 + 2X3 =7.
(c) 4Yl + 2Y2 + Y3 + 5Y4 = 52.9, 3Yl + Y2 + 4Y3 + 7Y4 = 74.2,
5.
Problems 243
2Yl + 3Y2 + Y3 + 6Y4 = 58.3, 3.Yl + Y2 + Y3 + 3Y4 = 34.2.
Multiloop Circuits II Find the currents i1 through i3 in the circuit diagrammed in Figure 5.P4.
~
a~----~r+----~----~
b
Figure 5.P4
A multi-loop circuit.
The resistances are listed in the following table:
10 ohms 20 ohms 50 ohms
Material Balances on a Gas Absorber The following equations are material balances for CO2, S02, and N2 around the gas absorber shown in Figure S.PS.
Figure 5.PS Gas absorber.
Stream 51 is known to contain 99 mole % mono ethanolamine (MEA) and 1 mole % CO2, The now rate in 51 is 100 moles per minute. The compositions (mole fractions) used in the material balances are tabulated as
244 Chapter 5 Matrix Operations in Excel
Figure 5.P6
low-cost, high"performance, chemical extraction unit (coffee maker).
o o 0.99000
0.01651 o 0.90800
0,00220 0.98900 o
0.02000 0.90000 o
CO2 Balance:
CO2 in 51 + CO2 in 53 "" CO2 in 52 + CO2 in 54
1 mole + 0.08000.53 := 0.07522.52 + 0.00880· S4 502 in 51 + 502 in S3 = 502 in 52 + 502 in 54
o + 0.02000.53 =.: 0.01651 .52 + 0.00220.54
N2 in 51 + N2 in S3 = N2 in 52 + N2 in 54
o + 0.90000.53 = 0 + 0.98900· SA
502 Balance:
N2 Balance:
Solve the material balances for the unknown flow rates, S2 through S4.
5.6. Material Balances on an Extractor This problem focuses on a low-cost, high" performance, chemical extraction unit: a drip coffee maker. (See Figure 5.P6.) The ingredients are water, coffee solubles (CS), and coffee grounds (CG).
Stream is
1 % soluble ingredients. The product coffee (S3) contains 0.4% CS and 99.6% water. Finally, the waste product (54) contains 80% CG, 19.6% water, and 0.4% CS. (All percentages are on a volume basis.) The following is a diagram of the unit:
,--------------------
i
I
i Ol
S2; CS, COl/I
:~I :~I
I~
I I
I
I
I I J
v.
.
,
I I I
: S3: cs. water
I
I
I I I
I
-------- - --1- ---- - .----
S<; CG, CS, water
Write the material balances on the water, CS, and CG.Then solve the mater" ial balances for the volumes S2 through S4'
5.7. Flash Distillation When a hot, pressurized liquid is pumped into a tank (flash unit) at a lower pressure, the liquid boils rapidly. This rapid boiling is called a nash. If the liquid contains a mixture of chemicals, the vapor and liquid leaving the flash unit will have different compositions, and the flash unit can be used as a separator. The physical principle involved is vapor-liquid equilibrium; the vapor and liquid leaving the flash unit are in equilibrium.This allows the composition of the outlet streams to be determined from the operating temperature
5.S
Problems 245
and pressure of the flash unit. Multiple flash units can be used together to separate multicomponent mixtures.
Figure S.P7
Two-unit flash distillation.
A mixture of methanol, butanol, and ethylene glycol is fed to a flash unit (Unit 1 in Figure S.P7) operating at 16SoC and 7 atm. The liquid from the
10,000 kg/h. Write material balances for each chemical, and solve for the mass flow rate of each product stream (Vl, V2, L2)' A material balance is simply a mathematical statement that all of the methanol (for example) going into the process has to come out again. (This assumes a steady state and no chemical reactions.) The following methanol balance is shown as an example:
methanol in F = methanol in Vi + methanol in V2 + methanol in Lz 0.3' (10,000 kg/h) = 0.716' VI + 0.533' Vz + 0.086· i.;
The compositions of the feed stream F and of the three product streams are listed here:
0.300
0.268 0.016
0.443 0.024
0.388 0.526
Wheatstone Bridge II Because the resistances of metals vary with temperature, measuring the resistance of a metal sensor inserted in a material is one way to determine the temperature of the material. Resistance temperature detectors (RTDs) are devices commonly used to make temperature measurements.
To compute the resistance of the RTD, it can be built into a Wheatstone Bridge as the unknown resistance R3, in Figure S.PS.
246 Chapter 5 Matrix Operations in Excel
(I
c
d
b
E
+ .-
Figure S.PS Wheatstone Bridge.
computed from the known resistances, R 1 and R2, and the setting on the potentiometer, R4:
(5.18)
c r
TIle temperature can be determined from the resistance as
s. sl
RT = Ro[1 + nT],
(5.19)
vr
where
Ro
is the resistance at the unknown temperature, T;
is the resistance at ODe (known, one of the RTD specifications); and is the linear temperature coefficient (known, one of the RTD specifications).
(a) For the known resistances and battery potential listed next, what is the resistance of the RTD when the potentiometer (R4) has been adjusted to 24 ohms to balance the bridge?
(b) Use Kirchhoff's laws to find currents il through I}.
24 volts 15 ohms 15 ohms 40 ohms