392 CHAPTER 18. LINEAR FUNCTIONS

18.2.4 MATLAB and Matrix ArithmeticTo find the inverse of a square matrix in matlab, you open it and type the following. The>> will already be there. To enter a matrix, you list the rows in order from left to rightseparating the entries with commas or simply leaving a space. Then to start a new row, youenter ; a semicolon.

>>inv([1,2,3;5,2,7;8,2,1]) Then press enter and it will give the following:ans =-0.1667 0.0556 0.11110.7083 -0.3194 0.1111-0.0833 0.1944 -0.1111Note how it computed the inverse in decimals. If you want the answer in terms of

fractions, you should have the symbolic toolbox installed and then you do the following:>>inv(sym([1,2,3;5,2,7;8,2,1])) Then press enter and it will give the following:ans =[ -1/6, 1/18, 1/9][ 17/24, -23/72, 1/9][ -1/12, 7/36, -1/9]You can do other things as well. Say you have>>A=[1,2,3;5,2,7;8,2,1];B=[3,2,-5;3,11,2;-3,-1,5];C=[1,2;4,-3;7,3];D=[1,2,3;-3,2,1];This defines some matrices. Then suppose you wanted to find

(A−1DT +BC

)T. You

would then typetranspose(inv(sym(A))*transpose(D)+B*C) or (inv(sym(A))*D’+B*C)’and press enter. This givesans =[ -427/18, 4421/72, 1007/36][ -257/18, -1703/72, 451/36]In matlab, A’ means ĀT the conjugate transpose of A. Since everything is real here, this

reduces to the transpose. Also, when entering a row in a matrix, it suffices to leave a spacebetween the entries, but you need ; to start a new row.

To get to a new line in MATLAB, you need to press shift enter. Notice how a ; wasplaced after the definition of A,B,C,D. This tells MATLAB that you have defined some-thing but not to say anything about it. If you don’t do this, then when you press return, itwill list the matrices and you don’t want to see that. You just want the answer. When youhave done a computation in MATLAB, you ought to go to >> and type “clear all” and thenenter. That way, you can use the symbols again with different definition. If you don’t dothe “clear all” thing, it will go on thinking that A is what you defined earlier.

18.3 Exercises1. Here are some matrices:

A =

(1 2 32 1 7

),B =

(3 −1 2−3 2 1

),

C =

(1 23 1

),D =

(−1 22 −3

),E =

(23

).

Find if possible −3A,3B−A,AC,CB,AE,EA. If it is not possible explain why.

392 CHAPTER 18. LINEAR FUNCTIONS18.2.4 MATLAB and Matrix ArithmeticTo find the inverse of a square matrix in matlab, you open it and type the following. The>> will already be there. To enter a matrix, you list the rows in order from left to rightseparating the entries with commas or simply leaving a space. Then to start a new row, youenter ; a semicolon.>> inv([1,2,3;5,2,7;8,2,1]) Then press enter and it will give the following:ans =-0.1667 0.0556 0.11110.7083 -0.3194 0.1111-0.0833 0.1944 -0.1111Note how it computed the inverse in decimals. If you want the answer in terms offractions, you should have the symbolic toolbox installed and then you do the following:>> inv(sym([1,2,3;5,2,7;8,2,1])) Then press enter and it will give the following:ans =[ -1/6, 1/18, 1/9][ 17/24, -23/72, 1/9][ -1/12, 7/36, -1/9]You can do other things as well. Say you have>>A=[1,2,335,2,7;8,2, 1];B=[3,2,-5;3,11,2;-3,-1,5];C=[1,2;4,-3;7,3];D=[1,2,3;-3,2,1];This defines some matrices. Then suppose you wanted to find (A~'D* +BC)". Youwould then typetranspose(inv(sym(A))*transpose(D)+B*C) or (inv(sym(A))*D’+B*C)’and press enter. This givesans =[ -427/18, 4421/72, 1007/36][ -257/18, -1703/72, 451/36]In matlab, A’ means A’ the conjugate transpose of A. Since everything is real here, thisreduces to the transpose. Also, when entering a row in a matrix, it suffices to leave a spacebetween the entries, but you need ; to start a new row.To get to a new line in MATLAB, you need to press shift enter. Notice how a ; wasplaced after the definition of A,B,C,D. This tells MATLAB that you have defined some-thing but not to say anything about it. If you don’t do this, then when you press return, itwill list the matrices and you don’t want to see that. You just want the answer. When youhave done a computation in MATLAB, you ought to go to >> and type “clear all” and thenenter. That way, you can use the symbols again with different definition. If you don’t dothe “clear all” thing, it will go on thinking that A is what you defined earlier.18.3. Exercises1. Here are some matrices:12a= (34c= (1 2)0-(4 4)e=(2).Find if possible —3A,3B —A,AC,CB,AE, EA. If it is not possible explain why.