1. Engineering
  2. Computer Science
  3. in this exercise we will compare in matlab the speed...

Question: in this exercise we will compare in matlab the speed...

Question details

In this exercise we will compare in MATLAB the speed of two methods for solving the system Ax = b when A is an invertible square matrix: computing the RREF and computing the LU factorization. Note that, although the number of operations for obtaining the LU factorization is the same as the gaussian elimination, the LU factorization has the advantage that once the matrix A is decomposed, the substitution step can be carried out efficiently for different values of b. Thus the LU factorization is certainly preferable when solving the system Ax = b with different values of b for the same A. We will use the MATLAB tic and toc command to measure the computation times. Enter A=rand (1000) ; x=ones (1000 , 1); b-A*x; Important: Be sure to use semicolon after each command so that matrices and vectors are not displayed. Do not print or include these large matrices and vectors in your lab write-up. (a) Solve Ax = b using the reduced row echelon form and store the solution in x.rref: tic; R= rref ( [A, b]); x-rref = R(: ,end); toc (make sure that all the commands are on the same line) (b) Solve Ax = b using the LU factorization as you did in EXERCISE 4(a)(b), and calculate the elapsed time using the tic toc commands. Store the solution in x.lu. Which method is faster? NOTE: Make sure you use semicolon; the only output should be the elapsed time. Also, dont forget that, when using tic toc all the commands should be in one line, so you should find L,U,P, solve for y, and solve for x.lu all on one line (c) Compare the solutions from parts (a) and (b) with the exact solution x by computing norm(x rref - x) and norm(xlu - x). How accurate are the solutions from parts (a) and (b)?

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution