we are going to solve the system ax=b for different b ’s, where[-0.5 0.1 -2.0 ; 0.6 -1.7 -1.9; 0.3 0.3 0.1 ]how large can be the relative error of the right hand side in 2 -norm? in matlab

To solve the system AX=B for different B's in Matlab, you can use the following code:

main.m
A = [-0.5, 0.1, -2.0; 0.6, -1.7, -1.9; 0.3, 0.3, 0.1];
B1 = [1; 2; 3];
B2 = [4; 5; 6];
B3 = [7; 8; 9];
X1 = A\B1;
X2 = A\B2;
X3 = A\B3;
136 chars
8 lines

This will give you X1, X2 and X3 as solutions for each of the B's.

To calculate the maximum possible relative error of the right-hand side in 2-norm, you can use the following formula:

main.m
norm(A)\(norm(A)*norm(B-C))/norm(B)
36 chars
2 lines

where A is the coefficient matrix, B is the exact right-hand side (in this case, any of the B's), and C is the approximate right-hand side (in this case, any of the solutions X1, X2, or X3).

For example, to calculate the maximum possible relative error of B1, you can use the following code:

main.m
B = B1;
C = X1;
err = norm(A)\(norm(A)*norm(B-C))/norm(B);
59 chars
4 lines

This will give you the maximum possible relative error for B1. You can repeat the same for B2 and B3 to get the maximum possible relative error for those as well.

related categories

gistlibby LogSnag