?? ref1.m
字號:
% 《工程線性代數(MATLAB版)》第一章化為上三角行階梯形式子程序ref1
%
function [A,jb] = ref1(A,tol)
%REF1 求矩陣的普通行階梯形式
% R = RREF(A) 生成A的普通行階梯形式.
%
% [R,jb] = REF1(A) 同時返回數組 jb:
% r = length(jb) 是A的秩。
% x(jb) 為線性系統Ax = b中約束變量, ,
% A(:,jb) 是A空間中的一組基,
% R(1:r,jb) 是上三角矩陣.
%
% [R,jb] = REF1(A,TOL) 按給定的容差判斷秩.
%
% 舍入誤差可能使此程序算出的秩與用 RANK, ORTH and NULL等函數算出的不同.
%
% 參閱 RREFMOVIE, RANK, ORTH, NULL, QR, SVD. RREF
% CBM, 11/24/85, 1/29/90, 7/12/92.
% Copyright 1984-2001 The MathWorks, Inc.
% $ 5/19/2006 陳懷琛修改
[m,n] = size(A);
% Does it appear that elements of A are ratios of small integers?
[num, den] = rat(A);
rats = isequal(A,num./den);
% Compute the default tolerance if none was provided.
if (nargin < 2), tol = max(m,n)*eps*norm(A,'inf'); end
% Loop over the entire matrix.
i = 1;
j = 1;
jb = [];
while (i <= m) & (j <= n)
% Find value and index of largest element in the remainder of column j.
[p,k] = max(abs(A(i:m,j))); k = k+i-1;
if (p <= tol)
% The column is negligible, zero it out.
A(i:m,j) = zeros(m-i+1,1);
j = j + 1;
else
% Remember column index
jb = [jb j];
% Swap i-th and k-th rows.
A([i k],j:n) = A([k i],j:n);
% Divide the pivot row by the pivot element.
%% A(i,j:n) = A(i,j:n)/A(i,j);
% Subtract multiples of the pivot row from all the other rows.
for k = [i+1:m]
A(k,j:n) = A(k,j:n) - A(k,j)*A(i,j:n)/A(i,j);
end
i = i + 1;
j = j + 1;
end
end
% Return "rational" numbers if appropriate.
if rats
[num,den] = rat(A);
A=num./den;
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -