MATLAB Exercise 2 School of mathematical ces Xiamen University httplgdipke.xmuedu MATLAB Exercise 2 -Solving Linear Systems of Equations 1. Generate random5×5 matrices with integer entries(元素) by setting A-round(10*rand(5) and B=round(20*rand(5))-10 Use MATLAB to compute each of the following pairs of numbers In each case check whether he first is equal to the second a)AA b)JA+B AF+[B C)AB AlBI d)A'B'||A'‖B’l e)|+11f|AB1141 inv(X) returns the inverse of the square matrix X elp inv(A)returns the inverse of the square matrixa det(A)returns the determinant of the square matrix A A returns the conjugate transpose of A 2. Set A-round(10 *rand(6)). In each of the following, use MATLAb to compute a second matrix as indicated. State how the second matrix is related to A and compute the determinants of both matrices. How are the determinants related? a)B=A;B(2,)=A(1,),B(1,}=A(2,:) b)C=A;C(3,)4*A(3,:) c)D=A,D(5,)=A(5,)+2*A(4,) 3. Use Cramer's rule(det), backslash () operation, inv function, rref function respectively to solve the following systems. And check whether the results are the exact solutions of the corresponding equations. If not, try to show the reason x1+2x2=4 5x1+x2=4 4x,+2x-x,=2 x+3x2+x3=1 c){3x-x2+2x3=10 5 llx1+3x2=8 2x,+2 lp In command window input help rref to see the usage of this function 4. Let A=2 3 4, compute the third of column of A" by using Cramer's rule to solve Ax=e3. The result should be displayed in rational format 5. Let a be the matrix in ex4. Compute the adj A(A的伴随矩阵) by using the inv and det function 6. Compute the general solution of the following linear systems by using backslash (1), null and rref function x1+x2-5x3 x1+x2-5x3 a)14x+5x2+x=8 b){4x+5x+x1=8 2x+4x,+4x2=8 Ex2-1
MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Ex21 MATLAB Exercise 2 Solving Linear Systems of Equations 1. Generate random 5×5 matrices with integer entries(元素) by setting A=round(10*rand(5)) and B=round(20*rand(5))10 Use MATLAB to compute each of the following pairs of numbers. In each case check whether the first is equal to the second. a) |A| |A’| b) |A+B| |A|+|B| c) |AB| |A||B| d) |A’B’| |A’||B’| e) 1 | A | - 1 | A| f) 1 | AB | - | | | | A B inv(X) returns the inverse of the square matrix X Help inv(A) returns the inverse of the square matrix A det(A) returns the determinant of the square matrix A A’ returns the conjugate transpose of A 2. Set A=round(10*rand(6)). In each of the following, use MATLAB to compute a second matrix as indicated. State how the second matrix is related to A and compute the determinants of both matrices. How are the determinants related? a) B=A; B(2, :) = A(1, :); B(1, :)=A(2, :) b) C=A; C(3, :)=4*A(3, :) c) D=A; D(5, :)=A(5, :)+2*A(4, :) 3. Use Cramer’s rule (det), backslash (\) operation, inv function, rref function respectively to solve the following systems. And check whether the results are the exact solutions of the corresponding equations. If not, try to show the reason. a) 1 2 1 2 2 4 2 2 2 x x x x Ï + = Ì - = Ó b) 1 2 1 2 2 3 1 5 4 x x x x Ï + = - Ì + = Ó c) 1 2 3 1 2 3 1 2 4 2 2 3 2 10 11 3 8 x x x x x x x x Ï + - = Ô Ì - + = Ô + = Ó d) 1 2 3 1 2 3 1 2 3 3 1 2 5 2 2 8 x x x x x x x x x Ï + + = Ô Ì + + = Ô - + - = - Ó Help In command window input help rref to see the usage of this function 4. Let 1 2 3 2 3 4 5 4 6 A = , compute the third of column of 1 A - by using Cramer’s rule to solve Ax=e3. The result should be displayed in rational format. 5. Let A be the matrix in Ex4. Compute the adj A (A 的伴随矩阵) by using the inv and det function. 6. Compute the general solution of the following linear systems by using backslash(\), null and rref function. a) 1 2 3 1 2 3 1 2 3 2 3 0 4 5 8 2 4 2 x x x x x x x x x Ï + - = Ô Ì + + = Ô - - + = Ó b) 1 2 3 1 2 3 1 2 3 2 3 0 4 5 8 2 4 4 8 x x x x x x x x x Ï + - = Ô Ì + + = Ô + + = Ó
MATLAB Exercise 2 School of Mathematical Sciences Xiamen University httplgdipke.xmuedu 2x1+x,-3x3=0 7. Compute the general solutions of 4x,+5x2+x,=0 by using rref function 2x1-2x2-10x3=0 8.+ Use rand function to generate several4×3,3×1,3×4,4× I matrices, compare the results of the corresponding linear systems computed by \ inv and pinv Help pinv(A)returns the Moore-Penrose pseudoinverse of A, where A need not be a square matrIx 9. *Use rand to generate a linear system Ax=b. Try the display the result if r(a br(A); else display There is no solution. " (if) 10. Set A=11; 2 4 2: 21 1: B=3 12; 122: 314; C=A+i*B Use MATLAB to compute each of matrices. In each case check whether the first is equal to the If they are equal then display The first matrix is equal to the second one. Otherwise display The first matrix is not equal to the second one 2)A A 3)inv(A)pinv(A) 4)inv(B)pinv(B) Held A'returns the conjugate transpose of A A. returns the transpose of A nj (A)returns the conjugate of A 11. Use help to study functions: trace, rank, conj, rref, rrefmovie, format Ex2-2
MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Ex22 7. Compute the general solutions of 1 2 3 1 2 3 1 2 3 2 3 0 4 5 0 2 2 10 0 x x x x x x x x x Ï + - = Ô Ì + + = Ô - - = Ó by using rref function. 8. *Use rand function to generate several 4×3, 3×1; 3×4, 4×1 matrices, compare the results of the corresponding linear systems computed by \, inv and pinv. Help pinv(A) returns the MoorePenrose pseudoinverse of A, where A need not be a square matrix. 9. *Use rand to generate a linear system Ax=b. Try the display the result if r(A b)=r(A); else display “There is no solution.” (if) 10. Set A=[1 2 1; 2 4 2; 2 1 1]; B=[3 1 2; 1 2 2; 3 1 4]; C=A+i*B. Use MATLAB to compute each of the following pairs of matrices. In each case check whether the first is equal to the second. If they are equal then display ‘The first matrix is equal to the second one.’ Otherwise display ‘The first matrix is not equal to the second one.’ 1) C’ C.’ 2) A’ A.’ 3) inv(A) pinv(A) 4) inv(B) pinv(B) Help A’ returns the conjugate transpose of A A.’ returns the transpose of A conj(A) returns the conjugate of A 11. Use help to study functions: trace, rank, conj, rref, rrefmovie, format