NUMERICAL ANALYSIS + MATLAB (Assignment)
NUMERICAL ANALYSIS + MATLAB (Assignment)
only “one” page report
in the assignment attached, there is a demo for matlab
this is the demo:
Gaussian Elimination in floating point arithmetic
Note: Download the in-class demo LSRandom.m before completing this assignment.
*((here is the code for this part for matlab)):
% Class: MACM 316 % Title: Gaussian Elimination for a random matrix demo % Description: Computes the mean solution error over Ntr trials for the % system Ax=b where A is a random NxN matrix and x is a vector of ones. % Plots the result as a histogram. % File name: LSRandom.m N = 10; % Matrix size Ntr = 100; % Number of trials errs = zeros(Ntr,1); % Vector of errors x = ones(N,1); % exact solution vector for i=1:Ntr A = randn(N,N); % Construct a random NxN matrix (normally distributed) b = A*x; % Compute the right-hand side vector z = Ab; % Solve the linear system errs(i) = max(abs(z-x)); % Compute the error end % Compute the mean and standard deviation of the error mean_err = mean(errs) sdev_err = sqrt(var(errs)) % Plot a histogram of the errors hist(log10(errs),10) title(['histogram of log_{10}(error) for ' num2str(Ntr) ' solves with a ' num2str(N) 'x' num2str(N) ' matrix'],'fontsize',14) xlabel('log_{10}(error)','fontsize',12) ylabel('number','fontsize',12)