⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo_lu_fl.m

📁 DEMO_COND demonstrates the role of the condition number of a matrix (with respect to inversion)
💻 M
字号:
%  Solve a random linear system using the LU-decomposition%  in a decimal floating point system using a mantissa length %  of m%%  Matthias Heinkenschloss%  Department of Computational and Applied Mathematics%  Rice University%  Feb 12, 2001%clear;% fprintf(1, 'Solve a random linear system using the LU-decomposition \n' )fprintf(1, 'in a decimal floating point system using a mantissa length of m \n')% Use floating point arithmeticarith = 'r';% Set the dimension of the system and compute the matrix% A and the exact solution x using the random number generator.n    = 5;A_ex = 10*rand(n);x_ex = 10*rand(n,1);% Compute the corresponding right hand sideb_ex = A_ex * x_ex;fprintf(1, 'The condition number of A is  %12.6e \n', cond(A_ex) )% compute the solution of the linear system using % the LU-decomposition with pivoting and various % mantissa length% print header for absolute and relative errorsfprintf(1, '       Absolute      Relative  \n')fprintf(1, '  m    Error         Error  \n')for m = 1:20    A = A_ex;    b = b_ex;    [A, ipivt, iflag] = lu_pp_fl( A, m, arith );    if( iflag == 0 )         [b, iflag] = lu_pp_sl_fl( A, b, ipivt, m, arith );    end%   if a solution is computed, compute the relative and%   absolute error between computed and exact solution.    if( iflag > 0 ) %       matrix is detected to be singular. No solution %       is computed, set error equal to infinity        abserr(m) = inf;        relerr(m) = inf;     else        abserr(m) = norm(x_ex - b);        relerr(m) = abserr(m) / norm(x_ex);    end    %   print absolute and relative errors    fprintf(1, '%3i  %12.6e  %12.6e \n', m, abserr(m), relerr(m) );end%   plot absolute and relative errorssemilogy((1:20),abserr,'r'); hold on;semilogy((1:20),relerr,'b'); hold off;title( 'Absolute (red) and relative (blue) error in solution' );xlabel(' Mantissa length m ');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -