Exercise 2. Matrix Condition Number Consider a linear system Ha b with [hulnys1
ID: 2262045 • Letter: E
Question
Exercise 2. Matrix Condition Number Consider a linear system Ha b with [hulnys1 and right-hand side b = [bi, bn]T with coefficients The exact solution of this linear system is given as (a) Write a MATLAB function HilbertLs [H,b,x) function = HilbertLS (n) which will generate Hilbert matrix H and vectors b and z of size n. Hint: You can compare your Hilbert matrix with the one generated by the MATLAB function hilb. (2 pts.) (b) Using a MATLAB function | write a MATLAB script testHilbertLS to solve a linear system Hb, for with matrix H and vector b generated with function HilbertLS. Obtain an approximate solution n 5, 10, 15, 20. The condition number of matrix A defined as measures the sensitivity of matrix A to small perturbations in its coeficients. The MATLAB function cond determines the condition number of a matrix. Use this function to compute the matrix H condition number for n = 5, 10, 15, 20, what can you say about the relation between matrix H condition number and the results for various values of n? Present your results as a table, i.e.. rl 10 15 20 Hint: Use MATLAB function norm for the matriz 2-norm llAlla := max[Ax112 with x E Rn , where 2-1 lla := v/T+_+ defines Euclidean norm or 2-norm of vector z. (3 pts.)Explanation / Answer
function [H b x]=HilbertLS(n)
for i=1:n
for j=1:n
h(i,j)=1/(i+j-1);
end
end
for i=1:n
b(i)=(1/i)-(1/(i+n-1));
end
x(1)=1;
for i=2:n-1
x(i)=0;
end
x(n)=1;
H=h;
end
%% call the function
clc;
clear all;
k=1;
n=5;
while(k<5)
[H b x]=HilbertLS(n);
x1=H/b;
y=norm(abs(x1-x'));
H1(k)=norm(H)*norm(inv(H));
y1(k)=y;
n=n+5;
k=k+1;
end
disp('n ||x-x-2|| K2(H)')
disp('___________________________________________________________--')
for i=1:4
fprintf('%d %10f %10f ',5*i,y1(i),H1(i))
end
n ||x-x-2|| K2(H)
___________________________________________________________________
5 1.239100 476607.250243
10 1.359839 16024349468710.807000
15 1.411610 162050145716752030.000000
20 1.442400 8427197267216130000.000000
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.