condnum.m

来自「matlab算法集 matlab算法集」· M 代码 · 共 31 行

M
31
字号
function y = condnum (A,m)
%----------------------------------------------------------------
% Usage:       y = condnum (A,m)
%
% Description: Compute the estimated or exact condition number of
%              the n by n matrix A using the infinity norm:
%
%                 K(A) = ||A|| ||inv(A)||
%
% Inputs:      A = n by n matrix 
%              m = number of vectors used to estimate K(A)  
%                  (1 <= m <= n).  If m = n, then the exact K(A) 
%                  is computed using inv(A).
%
% Outputs:     y = condition number K(A) of A.  
%----------------------------------------------------------------
n = size(A,1);
if (m <= 0)
   y = cond (A,1);
else
   y = 0;
   for i = 1 : m
      b = randu(n,1,-1,1);
      x = A\b;
      y = max(y,norm(x,inf)/norm(b,inf));
   end
   y = y*norm(A,1);
end  
%----------------------------------------------------------------

⌨️ 快捷键说明

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