Question: Please answer all parts in MATLAB. functionv=rvect(m)v=fix(10rand(m,1)); Question 1. Row Operations and LU Factorization In this problem you will use MATLAB to carry out elementary
Please answer all parts in MATLAB.



functionv=rvect(m)v=fix(10rand(m,1)); Question 1. Row Operations and LU Factorization In this problem you will use MATLAB to carry out elementary row operations and to obtain the matrix factorization A=LU for a square 33 matrix A. Random Seed: Initialize the random number generator by typing rand('seed', abcd) where abcd are the last four digits of your student ID number. This will ensure that you generate your own particular random vectors and matrices. BE SURE TO INCLUDE THIS LINE IN YOUR LAB WRITE-UP. (a) Generate a random 33 matrix A and calculate the three principal minors of A. A=rand(3),A(1,1),det(A(1:2,1:2)),det(A) The factorization A=LU is only possible when all the principal minors are nonzero. Since A is a random matrix, this condition is almost certainly satisfied. If any of the numbers after the matrix A is zero (this is very unlikely to happen), repeat this step until you generate a matrix A with all three numbers after A nonzero. INCLUDE ALL THE MATRICES THAT YOU GENERATE THIS WAY IN YOUR LAB REPORT. When you have a matrix A for which all three principal minors are nonzero, you can transform A into an upper-triangular matrix U using only one type of row operation: adding a multiple of one row to a row below. You will choose multipliers to put zeros below the diagonal elements. At the end of the LU algorithm U will be upper triangular. Start by entering the initial value U=A in Matlab. Now use the Matlab editor to create an m-file called col1.m with the following MATLAB commands: L1=eye(3)L1(2,:)=L1(2,:)(U(2,1)/U(1,1))L1(1,:);L1(3,:)=L1(3,:)(U(3,1)/U(1,1))L1(1,:);L1 (notice the use of ; to suppress screen output of the intermediate results). This m-file requires a 33 matrix U to be already defined in your workspace. Execute this file by typing coll at the MATLAB prompt. The matrix L1 should be unit lower triangular with nonzero entries only on the diagonal and in column 1 . Set U=L1U using MAtLAB. Remember that the command X=Y in MAtLAB means to replace the current value of the variable X by the current value of the variable Y ). The new matrix U should have zeros in the first column below the main diagonal. Describe in words the row operations that change the old value of U into the new value of U. Use symbolic reference to the entries in U as in the col1.m code. Don't use the specific decimal entries in U. (b) The next step in the LU factorization is to put a zero below the main diagonal in column 2 of Use Use the MatLAB editor to create an m-file called col2.m with the commands L2=eye(3);L2(3,:)=L2(3,:)(U(3,2)/U(2,2))L2(2,:);L2 This will be used with the matrix U modified as in (a). Execute this file by typing col2 at the MATLAB prompt. The matrix L2 should be unit lower triangular with nonzero entries only on the diagonal and in column 2. Now set U= L2*U using MatLAB. The new matrix U should have all zeros below the main diagonal. Describe in words the row operations that change the old value of U into the new value of U. Use symbolic reference to the entries in U as in the col2.m code. Don't use the specific decimal entries in U. Use MatLAB to verify that U=L2L1A. (c) To complete the A=LU factorization, calculate inv(L1),inv(L2),L=inv(L1)inv(L2) Notice that column 1 of L is the same as column 1 of inv(L1 ) and column 2 of L is the same as column 2 of inv(L2 ). (See page 155 of the text.) Check by MatLaB that A=LU. Question 2. Using LU Factorization to Solve Ax=b (a) Inverting L and U : Let L and U be the matrices from Question \#1(c). Give a formula for the inverse matrix inv(L) in terms of the matrices L1 and L2. Then calculate inv(L) and inv(U) using MatLab. Notice that both of these matrices are in triangular form. (b) Solving Ax=b using L1 and U1 (See Example 4 on page 158 of the text): Use the m-file rvect.m from Lab 2 to generate a random integer vector b=rvect(3). Calculate the solution c=inv(L)b to the lower triangular system Lc=b. Then calculate the solution x=inv(U)c to the upper triangular system Ux=c. Finally, calculate Ax and check that it is b (since the entries in b are integers, this should be obvious by inspection)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
