Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is code for GERandom.m % GERANDOM: Gaussian Elimination for a random matrix. % Compute the mean solution error over 'Mtry' trials for % the

image text in transcribed

Below is code for GERandom.m

% GERANDOM: Gaussian Elimination for a random matrix. % Compute the mean solution error over 'Mtry' trials for % the system A*x = b, where A is a random NxN matrix and % x is an N-vector (containing only 1's). % YOU NEED MODIFY THIS CODE FOR COMPUTING ASSIGNMENT 4 N = 10; % Matrix size Mtry = 100; % Number of trials -- CHANGE THIS! errs = zeros(Mtry, 1); % Vector of errors x = ones(N,1); % Exact solution for i = 1 : Mtry A = 2*rand(N,N)-1; % Random NxN matrix with entries in [-1, 1] b = A*x; % Right-hand side vector y = A \ b; % Approximate solution from GE errs(i) = max(abs(y-x)); % Max-norm error in y end % Compute mean and standard deviation of the error mean_err = mean(errs) sdev_err = sqrt(var(errs)) % Plot the errors on a semi-log scale semilogy(1:Mtry, errs) title(['Error from ' num2str(Mtry) ' solves with a ', ... num2str(N) 'x' num2str(N) ' random matrix']) xlabel('M (trial number)') ylabel('Error') grid on, shg
In class you have seen that finite-precision computations with Gaussian Elimination (such as that implemented in Matlab's backslash command) generates relatively small errors for small matrices like those we considered in lectures, but the error can grow much larger for when the matrix is larger. The purpose of this assignment is to quantify the growth of this error for large matrices that have random entries. Let A be an N N matrix with random entries sampled from a uniform distribution on (-1,1). The exact solution is set to z= (1, 1, ..., 1)" ER and then b= Ac is taken to be the corresponding right-hand side vector. The linear system Ax=b is then solved numerically with Matlab's backslash operator, using the command y = A b, which yields an approximate solution y = y ER. To measure the error between the exact solution x and the approximation y, we define = max 2;- yil to be the maximum component-wise difference between the two vectors (this is just the max-norm error). Since A is a random matrix, you need to run this calculation for a number of separate trials using different realizations of A in order to obtain a reasonable averaged value for e. Let M be the number of trials and suppose that for the kth trial the error is elk). Then you can define the mean (average) error as 1 01. 023 (1) +(2) + ... +eM) where the subscript N on En denotes the matrix size. The code GERandom.m provided to you computes this averaged error En for a collection of M random matrices all of size N. The goal of this assignment is for you to study the growth in the error En as N increases, and to estimate the size of the matrix N = N* for which the mean error in Gaussian Elimination reaches EN 1. In other words, you need to find the size N* for which the round-off error will grow to the same magnitude as the solution vector r (i.e., no significant digits of accuracy remain). In practice, N* is quite large and your computer will not have the processing power to find N* directly. Instead, you should extrapolate the data from your computations on a sequence of moderate-sized N values in order to estimate N*. To do so, generate a plot of log(EN) versus log(N) and then extend the data to EN = 1 using suitable extrapolation. Your conclusions should be explained in a one-page report which includes the following: A justification for the values of N and M that you chose. Your plot of log(EN) versus log(N). An explanation of how you do the extrapolation. An estimate of the size N* where you predict that the error En = 1. In class you have seen that finite-precision computations with Gaussian Elimination (such as that implemented in Matlab's backslash command) generates relatively small errors for small matrices like those we considered in lectures, but the error can grow much larger for when the matrix is larger. The purpose of this assignment is to quantify the growth of this error for large matrices that have random entries. Let A be an N N matrix with random entries sampled from a uniform distribution on (-1,1). The exact solution is set to z= (1, 1, ..., 1)" ER and then b= Ac is taken to be the corresponding right-hand side vector. The linear system Ax=b is then solved numerically with Matlab's backslash operator, using the command y = A b, which yields an approximate solution y = y ER. To measure the error between the exact solution x and the approximation y, we define = max 2;- yil to be the maximum component-wise difference between the two vectors (this is just the max-norm error). Since A is a random matrix, you need to run this calculation for a number of separate trials using different realizations of A in order to obtain a reasonable averaged value for e. Let M be the number of trials and suppose that for the kth trial the error is elk). Then you can define the mean (average) error as 1 01. 023 (1) +(2) + ... +eM) where the subscript N on En denotes the matrix size. The code GERandom.m provided to you computes this averaged error En for a collection of M random matrices all of size N. The goal of this assignment is for you to study the growth in the error En as N increases, and to estimate the size of the matrix N = N* for which the mean error in Gaussian Elimination reaches EN 1. In other words, you need to find the size N* for which the round-off error will grow to the same magnitude as the solution vector r (i.e., no significant digits of accuracy remain). In practice, N* is quite large and your computer will not have the processing power to find N* directly. Instead, you should extrapolate the data from your computations on a sequence of moderate-sized N values in order to estimate N*. To do so, generate a plot of log(EN) versus log(N) and then extend the data to EN = 1 using suitable extrapolation. Your conclusions should be explained in a one-page report which includes the following: A justification for the values of N and M that you chose. Your plot of log(EN) versus log(N). An explanation of how you do the extrapolation. An estimate of the size N* where you predict that the error En = 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions