Question: Instructions: For the following three problems,follow the instructions in LAB 1 to create a diary text file. I. (a) Set n 1000 and generate an




Instructions: For the following three problems,follow the instructions in LAB 1 to create a diary text file. I. (a) Set n 1000 and generate an nx n matrix and two vectorsin R", having integer entries, by setting A-floor (10 rand (n)) b-sum (A') z-ones (n,1); The exact solution of the system Ax = b is the vector z. i) One could compute the solution in MATLAB using the " operation or by computing A and then multiplying Aimes b. Let us compare these two computational methods for both speed and accuracy. The inverse of the matrix A can be computed in MATLAB by typing inv(A). One can use MATLAB tic and toc commands to measure the elapsed time for each computation. To do this, use the commands tic, x- Alb; toc tic, y-inv(A) b toc (Make sure the 'tic toc' are on the same line) Which method is faster? (ii) To compare the accuracy of the two methods, we can measure how close the computed solutions x and y are to the exact solution z. One way to do this is to compute the sum of the absolute values of the components of the difference of the two vectors, that is. ?:-1 I?i-zil and ?"-1 lyi-11. To evaluate these sums in MATLAB we use the following commands: sum(abs (x - z)) sum (abs(y z)) Since we are finding the difference between the computed solution and the exact solution the smaller number is associated with the method that is more accurate. Recall that x was computed using the "" operation, while y was computed using the inverse. What method produces the most accurate solution? (b) Repeat part (a) using 2000 and n-5000 (c) Explain why the exact solution of the system Ax b is the vector z. Hint: Try computing Az for a 2 x 2 or 3 x 3 matrix by hand. Then figure out what b-sum (A the matrix A. Then compare Az to b. is in terms of
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
