we are going to solve the system ax = b for different b’s, where a =   1.8 0.1 0.1 −1.0 −2.0 0.2 1.0 −1.3 1.3   we know that the relative error of the right hand side is at most 0.0120 in 1-norm in matlab

We can use MATLAB to solve the system ax=b for different values of b with the given matrix a and maximum relative error of 0.0120 in 1-norm. One way to do this is to use the \ operator to perform the matrix division x=a\b, which will give us the solution x for the given right-hand side b.

To introduce the maximum relative error, we can use the norm function to calculate the 1-norm of the error e=b-a*x and compare it to the 1-norm of b multiplied by the maximum relative error. If the error is too large, we can adjust b and try again.

Here's some MATLAB code to implement this approach:

main.m
% define the matrix and maximum relative error
a = [1.8, 0.1, 0.1; -1.0, -2.0, 0.2; 1.0, -1.3, 1.3];
max_rel_error = 0.0120;

% loop over different right-hand side vectors
for i = 1:10  % for example, try 10 different b vectors
  % generate a random b vector with norm 1 and maximum relative error
  b = rand(3,1);
  b = b / norm(b,1);  % normalize b to have 1-norm of 1
  b = b + max_rel_error*randn(3,1);  % add random noise with maximum relative error
  b = b / norm(b,1);  % renormalize to ensure 1-norm of 1
  
  % solve the system and check the error
  x = a \ b;
  e = b - a*x;
  if norm(e,1) > max_rel_error*norm(b,1)
    disp(['Error too large for b = ', num2str(i)]);
  end
  
  % do something with the solution x
  disp(['Solution for b = ', num2str(i)]);
  disp(x);
end
782 chars
24 lines

This code loops over 10 different randomly generated right-hand side vectors, each with 1-norm of 1 and maximum relative error 0.0120. It solves the system for each b using the \ operator, checks the error using the norm function, and displays the solution x for each b.

Note that the actual values of b that we get will depend on the problem we are trying to solve, and the way we generate them will also depend on the specific requirements of the problem.

gistlibby LogSnag