【MATLAB】施密特正交化和归一化的MATLAB实现
function [B,C] = Schmidt_orthogonalization(A)
% 函数功能:施密特正交化
% 格式:[B,C] = Schmidt_orthogonalization(A)
% 输入A:需要施密特正交化的矩阵(横排列即可)
% 输出B:施密特正交化(未归一化)的矩阵(横排列)
% 输出C:施密特正交化(并归一化)的矩阵(横排列)
sz = size(A);
h = sz(1);
B = zeros(sz);
C = zeros(sz);
B(1,:) = A(1,:);
for i = 2:h
B(i,:) = A(i,:);
for j = 1:i-1
B(i,:) = B(i,:) - dot(A(i,:),B(j,:))/dot(B(j,:),B(j,:))*A(j,:);
end
end
for i = 1:h
C(i,:) = B(i,:)/norm(B(i,:),2);
end
end
举个例子:
>> A
A =
4 -3 1 0 0
1 -1 0 1 0
4 -5 0 0 1
>> [B,C] = Schmidt_orthogonalization(A)
B =
4.0000 -3.0000 1.0000 0 0
-0.0769 -0.1923 -0.2692 1.0000 0
-1.3554 -0.8369 -1.1923 -0.5862 1.0000
C =
0.7845 -0.5883 0.1961 0 0
-0.0728 -0.1821 -0.2549 0.9469 0
-0.5886 -0.3634 -0.5178 -0.2546 0.4343