子空间夹角计算-MATLAB源代码修正

2017-01-16  by:CAE仿真在线  来源:互联网

function theta = subspace(A,B)
%SUBSPACE Angle between subspaces.
% SUBSPACE(A,B) finds the angle between two subspaces specified by the
% columns of A and B.
%
% If the angle is small, the two spaces are nearly linearly dependent.
% In a physical experiment described by some observations A, and a second
% realization of the experiment described by B, SUBSPACE(A,B) gives a
% measure of the amount of new information afforded by the second
% experiment not associated with statistical errors of fluctuations.
%
% Class support for inputs A, B:
% float: double, single

% The algorithm used here ensures that small angles are computed
% accurately, and it allows subspaces of different dimensions following
% the definition in [2]. The first issue is crucial. The second issue is
% not so important; but since the definition from [2] coinsides with the
% standard definition when the dimensions are equal, there should be no
% confusion - and subspaces with different dimensions may arise in
% problems where the dimension is computed as the numerical rank of some
% inaccurate matrix.

% References:
% [1] A. Bjorck & G. Golub, Numerical methods for computing
% angles between linear subspaces, Math. Comp. 27 (1973),
% pp. 579-594.
% [2] P.-A. Wedin, On angles between subspaces of a finite
% dimensional inner product space, in B. Kagstrom & A. Ruhe (Eds.),
% Matrix Pencils, Lecture Notes in Mathematics 973, Springer, 1983,
% pp. 263-285.

% Thanks to Per Christian Hansen
% Copyright 1984-2007 The MathWorks, Inc.
% $Revision: 5.10.4.3 $ $Date: 2007/09/18 02:15:38 $

% Compute orthonormal bases, using SVD in "orth" to avoid problems
% when A and/or B is nearly rank deficient.
A = orth(A);
B = orth(B);
%Check rank and swap
if size(A,2) < size(B,2)
tmp = A; A = B; B = tmp;
end
% Compute the projection the most accurate way, according to [1].
for k=1:size(A,2)
B = B - A(:,k)*(A(:,k)'*B);
end

% Make sure it's magnitude is less than 1.
theta = asin(min(ones(superiorfloat(A,B)),(norm(B))));


%说明

以下代码

for k=1:size(A,2)
B = B - A(:,k)*(A(:,k)'*B);
end


相当于如下公式计算:

B = (eye(size(A,1))-A*A')*B;

这样可以减少循环次数,提高计算速度;



矩阵B的特征值即为夹角正弦值

theta = asin(min(ones(superiorfloat(A,B)),(norm(B))));


superiorfloat() 返回 'single','double'...即A,B的数据类型

ones('double') 返回 1

以上代码说明,夹角正弦值应该小于等于1,当B的特征值大于1时,取1。




开放分享:优质有限元技术文章,助你自学成才

相关标签搜索:子空间夹角计算-MATLAB源代码修正 MatLab培训 MatLab培训课程 MatLab在线视频教程 MatLab技术学习教程 MatLab软件教程 MatLab资料下载 MatLab代做 MatLab基础知识 Fluent、CFX流体分析 HFSS电磁分析 Ansys培训 Abaqus培训 

编辑
在线报名:
  • 客服在线请直接联系我们的客服,您也可以通过下面的方式进行在线报名,我们会及时给您回复电话,谢谢!
验证码

全国服务热线

1358-032-9919

广州公司:
广州市环市中路306号金鹰大厦3800
电话:13580329919
          135-8032-9919
培训QQ咨询:点击咨询 点击咨询
项目QQ咨询:点击咨询
email:kf@1cae.com