Matlab Engineering math The Hilbert matrix is a special n ti
Matlab, Engineering math
The Hilbert matrix is a special n times n matrix whose (i, j)th entry is given by H_i, j = 1/(I + j - 1) The Hilbert matrix becomes very poorly conditioned even for moderate values of n. For each n = 1, 2, 3, ..., 12 create the n times n Hilbert matrix H using the MATLAB command hilb (type help hilb to get information about the function). Create an exact solution x consisting of a column vector of n ones. Then create a right hand side b = Hx in MATLAB. Now solve Hx_c = b in MATLAB using the \\ command so that xc = H\\b Generally xc will not be exactly x due to rounding error. Compute the infinity norm of the error using the MATLAB function norm as follows: Err(n) = norm(x - xc, inf) and hence the relative error. Compute the condition number of H for each n using the MATLAB cond function. Print a nicely formatted table with three columns: n, the condition number, and the relative error in the solution. For n = 6 and 10 display the full solutions (ie all n entries in the vector x_c) to see how accurate are the solutions.Solution
warning(\'off\')
 fprintf(\"n-Order \\t \\t RelativeError \\t \\t condOfH\ \")
 fprintf(\"==================================================================\ \")
  for n=0:12
     % Hilbert Matrix with nxn
     H = hilb(n) ;
    
     % xc = H * b
     % Create b with nx1
    
     b = ones(n,1) ;
    
     xc = H \\ b ;
    
     Err = norm(xc-b,Inf) ;
    
     condOfH = cond(H) ;
    
     fprintf(\"%8.8f \\t \\t %8.8f \\t \\t %8.8f \ \",n,Err,condOfH);
end
 fprintf(\"==================================================================\ \");

