Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10.2 (a) Write a well-commented MATLAB function program zysolvecheck with input

ID: 2262408 • Letter: 1

Question

10.2 (a) Write a well-commented MATLAB function program zysolvecheck with input a number n that makes a random n × n matrix A and a random vector b, solves the linear system Ax = b, calculates the scalar residual r = Ax-b], and outputs that number as r. (b) Write a well-commented MATLAB script program that calls mysolvecheck 10 times each for n = 10, 50, 100, 500, and 1000, records and averages the results and makes a log-log plot of the average e vs. n. Increase the maximum n until the program stops running within 5 minutes Turn in the plot and the two programs

Explanation / Answer

function r = mysolvecheck(n)
A = -100 + rand(n,n) * 200;
B = -100 + rand(n,1) * 200;
X = linsolve(A, B);
r = norm( (A*X - B), Inf);
end


nValues = [10, 50, 100, 500, 1000];
r = [];

for i=1:length(nValues)
n = nValues(i);
rSum = 0;
for j = 1:10
rSum = rSum + mysolvecheck(n);
end  
r(i) = rSum /10;
end


loglog(nValues, r, '-s');
title('Linear Equations');
xlabel("n values"); ylabel("residual values");

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote