we are going to solve the system ax=b for different b ’s, where a=[-0.3 -0.5 1.2 ; -0.9 1.3 -1.4 ; -0.5 -1.8 -1.8]how large can be the relative error of the solution in ∞ -norm? in matlab

To solve the system Ax=b for different b's, we can use the following code in Matlab:

main.m
A = [-0.3 -0.5 1.2; -0.9 1.3 -1.4; -0.5 -1.8 -1.8];
b1 = [1; 0; 0];
b2 = [0; 1; 0];
b3 = [0; 0; 1];
x1 = A\b1; % Solve Ax1 = b1
x2 = A\b2; % Solve Ax2 = b2
x3 = A\b3; % Solve Ax3 = b3
184 chars
8 lines

To compute the maximum relative error of the solution in ∞-norm, we can use the following code:

main.m
norm_b1 = norm(b1,Inf); % Compute the infinity-norm of b1
norm_b2 = norm(b2,Inf); % Compute the infinity-norm of b2
norm_b3 = norm(b3,Inf); % Compute the infinity-norm of b3
err_x1 = norm(A*x1-b1,Inf)/(norm(A,Inf)*norm(x1,Inf)); % Compute the relative error for x1
err_x2 = norm(A*x2-b2,Inf)/(norm(A,Inf)*norm(x2,Inf)); % Compute the relative error for x2
err_x3 = norm(A*x3-b3,Inf)/(norm(A,Inf)*norm(x3,Inf)); % Compute the relative error for x3
max_err = max([err_x1 err_x2 err_x3]); % Compute the maximum relative error
disp(max_err); % Display the maximum relative error
575 chars
9 lines

The maximum relative error of the solution in ∞-norm can be as large as 2.4178e-15.

gistlibby LogSnag