2) Consider the Hilbert matrix, A, whose elements are given by i+j-1 Write a scr
ID: 3593900 • Letter: 2
Question
2) Consider the Hilbert matrix, A, whose elements are given by i+j-1 Write a script m-file to do parts (a)-(e) below. You will use the function norm(x) for the norm (which is the 2-norm), cond(A) for the condition number (which is the 2-norm condition number), and the relatively stable backslash "command to solve a linear system. Use MATLAB to do all the following computations: Page 3 of 4 a) Use nested loops to compute the matrix, A, for any You do not need to use loops for the remaining parts of the problem b) Let the exact solution to some problem, Ar-, be x = ones (n,l). For n = 10, use MATLAB to find b . Now, compute the solution x( of Ax = b using the backslash"", command Use your results from part (b) to help compute the following: c) Compute the relative backward eror d) Compute an upper bound for the relative forward error if the exact solution were not known. e) Compute the relative forward error f) According to our discussion in class, at most how many digits can be trusted in your solution for n- 10 if the exact solution were not known?Explanation / Answer
PLEASE REFER BELOW CODE
close all
clear all
clc
A = zeros(10,10); %generating matrix 10x10 with all zeros
n=10; %setting n=10;
%generating hilbert matrix
for i=1:n
for j=1:n
A(i,j) = 1/(i + j -1);
end
end
A %printing hilbert matrix A
x = ones(n,1) %generating column vector
b = A * x %computing b;
xc = A %computing xc
relative_backward_error = abs(xc- x)./x %relative forward error
PLEASE REFER BELOW OUTPUT
A =
Columns 1 through 6
1.0000 0.5000 0.3333 0.2500 0.2000 0.1667
0.5000 0.3333 0.2500 0.2000 0.1667 0.1429
0.3333 0.2500 0.2000 0.1667 0.1429 0.1250
0.2500 0.2000 0.1667 0.1429 0.1250 0.1111
0.2000 0.1667 0.1429 0.1250 0.1111 0.1000
0.1667 0.1429 0.1250 0.1111 0.1000 0.0909
0.1429 0.1250 0.1111 0.1000 0.0909 0.0833
0.1250 0.1111 0.1000 0.0909 0.0833 0.0769
0.1111 0.1000 0.0909 0.0833 0.0769 0.0714
0.1000 0.0909 0.0833 0.0769 0.0714 0.0667
Columns 7 through 10
0.1429 0.1250 0.1111 0.1000
0.1250 0.1111 0.1000 0.0909
0.1111 0.1000 0.0909 0.0833
0.1000 0.0909 0.0833 0.0769
0.0909 0.0833 0.0769 0.0714
0.0833 0.0769 0.0714 0.0667
0.0769 0.0714 0.0667 0.0625
0.0714 0.0667 0.0625 0.0588
0.0667 0.0625 0.0588 0.0556
0.0625 0.0588 0.0556 0.0526
x =
1
1
1
1
1
1
1
1
1
1
b =
2.9290
2.0199
1.6032
1.3468
1.1682
1.0349
0.9307
0.8467
0.7773
0.7188
xc =
1.0000
1.0000
1.0000
1.0000
1.0001
0.9998
1.0003
0.9997
1.0001
1.0000
relative_forward_error =
1.0e-03 *
0.0000
0.0001
0.0014
0.0127
0.0609
0.1683
0.2774
0.2692
0.1418
0.0313
>>
PLEASE POST SEPARATE QUESTION FOR (d) , (e) AND (f)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.