(Mostly MATLAB) An n times n matrix A has entries a_i, j = 5/(i + 2j - 1). (a) D
ID: 3848131 • Letter: #
Question
(Mostly MATLAB) An n times n matrix A has entries a_i, j = 5/(i + 2j - 1). (a) Design a MATLAB routine myA.m that constructs for arbitrary n the n times n matrix A, a column vector x of size n with all of its entries equal to 1, and another column vector b defined by b = Ax. (With b so defined, the exact solution to Ax = b is the column vector x of ones.) (b) For each value of n in the sequence n = 5, 6, , do the following. i. Call myA.m to generate the corresponding A and b. ii. Use the built-in MATLAB command x_c = A to obtain the computational solution x_c to the system Ax = b and display it. iii. Using infinity norms throughout, compute and display the norms of the residual r = b - Ax_c and of the error E = x_c - x, where x is the n -vector of ones and is the exact solution. iv. Estimate and display the condition number k(A) by using the MATLAB command contest (A, Inf). v. Compute and display the relative error ||E||/||x_c|| and the relative residual ||r||/(||A|| ||x_c||). Does the error satisfy the relationship ||E||/||x_c|| lessthanorequalto k (A) ||r||/||A|| ||x_c|| derived in class? How large can you take n before the error is 100%, i.e., no significant digits remain in the solution? As n varies, how does the number of correct digits in the computed solution relate to the condition number of the matrix A?Explanation / Answer
(a)
create a file named myA.m and paste below code into it.
function [b,A] = myA(n)
A = zeros(n,n);
for i = 1:n
for j = 1:n
A(i,j) = 5/(i + 2*j - 1) ;
end
end
x = ones(n,1);
b = A*x;
end
Sample Output:
(b)
i) Matlab code:
for n = 5:7
n
[b,A] = myA(n)
end
Sample Output:
ii)
Matlab code:
clc;
for n = 5:7
n
[b,A] = myA(n);
xc = A
end
Sample Output:
iii)
Matlab code:
clc;
for n = 5:7
n
[b,A] = myA(n);
xc = A;
r = b - A*xc
x = ones(n,1);
E = xc - x
end
Sample Output:
Note that you have posted multiple questions, so according to chegg rules, I have solved initial
4 subparts i.e. a), b. i, b.ii, b.iii.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.