Math311 Matlab and numerical analysis

User Generated



MATH 311

Emory University



Unformatted Attachment Preview

MATH 315, Fall 2022 Problem Set 4 September 16, 2022 Homework Team (team number): (team name) This assignment is associated with Chapter 3, Solution of Linear Systems. It illustrates numerical methods for solving linear systems of equations, i.e. Ax = b, and also some complexities introduced when solving this problem on a computer. 1. Consider the following system of equations: x1 + x2 + 2x3 = 8 −x1 − 2x2 + 3x3 = 1 3x1 − 7x2 + 4x3 = 10 (a) Use Gaussian elimination to find the A = LU factorization of A (by hand). Which built-in MATLAB function can be used to determine the LU factorization? Discuss the results you obtain when you implement this function. (b) Use Gaussian elimination to find the P A = LU factorization of A (by hand). Which built-in MATLAB function can be used to determine this factorization? (c) Use your factorization from 1a to determine A−1 . (Hint: Recall that A ∗ A−1 = A ∗ X = I.) Discuss one benefit of using the factorization for this problem. (Hint: The next problem might give you some ideas.) 2. In this problem we consider solving Ax = bk for a given n × n matrix A, and multiple right hand side vectors, b1 , b2 , . . . , bm . We will assume these vectors are stored in an n × m matrix B; that is,   B = b1 b2 · · · bm . We could: • Use Gaussian elimination to solve each system Ax = bk , or • first compute the P A = LU factorization, and then compute the solutions by using only backward and forward solves. 1 The purpose of this problem is to compare the time it takes for these two approaches. Here is code to illustrate how to do this comparison with 50 right hand side vectors: function [t1, t2] = CompareSpeed(n) % (add comments here) n_rhs = 50; n_runs = 10; A = rand(n); B = rand(n,n_rhs); t1_sum = 0; for j = 1:n_runs tic for k = 1:n_rhs x = A\B(:,k); end t1_sum = t1_sum + toc; end t1 = t1_sum/n_runs; t2_sum = 0; for j = 1:n_runs tic [L, U, P] = lu(A); for k = 1:n_rhs x = U\(L\(P*B(:,k))); end t2_sum = t2_sum + toc; end t2 = t2_sum/n_runs; (a) Implement and run the above function, and test for n = 50. (b) Add a few lines of comments (see the line (add comments here)) to explain the purpose of this function, inputs and outputs. (c) What is the purpose of the loop for j = 1:n runs? (d) Write a script that will run the function for n = 50, 100, 200, 400, 800, 1600, and plot the timings using both plot and semilogy. Your plots should have matrix size, n, on the x-axis, and time to solve on the y-axis. That is, your plots should look similar to the following, but you should add a legend to each of the plots to indicate which approach is associated with the blue curve, and which is associated with the red. 2 2 10 10 0 time to solve 1.5 time to solve 1 1 10 -1 10 -2 0.5 10 -3 10 -4 0 0 500 1000 1500 matrix size, n 0 500 1000 matrix size, n 3 1500
Purchase answer to see full attachment
Explanation & Answer:
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

View attached explanation and answer. Let me know if you have any questions..m file is inside the zip file. I have also attached the code in txt file and word file for 2c. Let me know if there is any queries.

The purpose of the loop for j=1:n_runs is to do multiple runs o...

Awesome! Perfect study aid.


Related Tags