In: Computer Science
4. For n = 50, 100, 200, 300, 400, do the following. Let A be the n × n matrix with entacries Aij = p 2(i − j) 2 + n/5. Define xexact = [1, 1, . . . , 1]T , and then compute b = Axexact. Using Matlab’s backslash, numerically solve the equation
Ax = b,
thereby producing a computed solution xc. In exact arithmetic xc = xexact of course, but in IEEE double precision xc will not equal xexact. The quantity kxc − xexactk∞ is the forward error. Construct a table which, for each n, collects the relative forward error, relative backward error, magnification factor, and (infinity-norm) condition number of A. Discuss your results.
format long
n=input('Enter the size of matrix: ')
A=zeros(n,n)
for i=l:n
for j=l:n
A(i,j)=(2*(i-j)^2+n/5)^(1/2)
end
end
x_exact=ones(n,l)
b=A*x_exact
x=A/b
bl=A*x
REF=norm((x-x_exact),inf)/norm(x_exact,inf) %Relative forward Error
RBE=norm((b-bl),inf)/norm(b,inf) %Relative Backward Error
MF=REF/RBE %Magnification Factor
k=cond(A,inf) %Condition number with infinity norm
N | Relative forward Error | Relative Backward Error | Magnification Factor | Condition number with infinity norm |
50 | 6.0513*10^-11 | 6.499*10^-16 | 9311*10^4 | 9.82*10^5 |
100 | 3.549*10^-9 | 6.463*10^-16 | 549*10^6 | 6.184*10^7 |
200 | 9.3077*10^-7 | 5.157*10^-16 | 1.804*10^9 | 1.29*10^10 |
300 | 4.639*10^-5 | 1.259*10^-15 | 3.683*10^10 | 6.2039*10^11 |
400 | 8.5488*10^-4 | 1.2876*10^-15 | 6063*10^11 | 1.475*10^13 |
I Hope its Helps you. If you have any doubts please ask in comments and please don't dislikes the solutions and Efforts of Experts. ANd Give a like to me.