we are going to solve the system ax=b for different b ’s, where a=[-1.6 -0.9 1.4 ; 1.6 -0.2 0.1;-1.5 0.1 -0.2]calculate the large relative error of the right hand side 1 -norm? in matlab

To solve the system Ax=b, we can use MATLAB's A \ b command. For different b's, we can put them in a matrix B where each column corresponds to a different b. Then we can use the same A and solve Ax=b for each column of B using A \ B.

To calculate the large relative error of the right hand side 1-norm, we can use the following steps:

  1. Solve Ax=b for each column of B using X = A \ B
  2. Calculate the new matrix B_new by multiplying A and X: B_new = A * X
  3. Calculate the difference between B and B_new: delta_B = B - B_new
  4. Calculate the 1-norm of B: norm_B = norm(B, 1)
  5. Calculate the 1-norm of delta_B: norm_delta_B = norm(delta_B, 1)
  6. Calculate the large relative error of the right hand side 1-norm: err = norm_delta_B / norm_B

Here's the MATLAB code to accomplish this:

main.m
A = [-1.6 -0.9 1.4; 1.6 -0.2 0.1; -1.5 0.1 -0.2];
B = [1 2 3; 4 5 6; 7 8 9];

X = A \ B;
B_new = A * X;
delta_B = B - B_new;
norm_B = norm(B, 1);
norm_delta_B = norm(delta_B, 1);
err = norm_delta_B / norm_B;
208 chars
10 lines

Note that I've used B = [1 2 3; 4 5 6; 7 8 9] as an example for B. You can replace it with any other matrix of appropriate dimensions.

related categories

gistlibby LogSnag