MATLAB中的随机正交矩阵

时间:2018-11-29 23:52:00

标签: matlab matrix random orthogonal

我有一个代码在Matlab中生成随机正交矩阵。

function M=RandOrthMat(n, tol)
% M = RANDORTHMAT(n)
% generates a random n x n orthogonal real matrix.
%
% M = RANDORTHMAT(n,tol)
% explicitly specifies a thresh value that measures linear dependence
% of a newly formed column with the existing columns. Defaults to 1e-6.
%
% In this version the generated matrix distribution *is* uniform over the manifold
% O(n) w.r.t. the induced R^(n^2) Lebesgue measure, at a slight computational 
% overhead (randn + normalization, as opposed to rand ). 
% 
% (c) Ofek Shilon , 2006.


    if nargin==1
      tol=1e-6;
    end

    M = zeros(n); % prealloc

    % gram-schmidt on random column vectors

    vi = randn(n,1);  
    % the n-dimensional normal distribution has spherical symmetry, which implies
    % that after normalization the drawn vectors would be uniformly distributed on the
    % n-dimensional unit sphere.

    M(:,1) = vi ./ norm(vi);

    for i=2:n
      nrm = 0;
      while nrm<tol
        vi = randn(n,1);
        vi = vi -  M(:,1:i-1)  * ( M(:,1:i-1).' * vi )  ;
        nrm = norm(vi);
      end
      M(:,i) = vi ./ nrm;

    end %i

end  % RandOrthMat

但是我不确定如何从此代码中获得1000个随机正交矩阵并将其用于我的代码中。

下面是在MATLAB中生成1000个随机矩阵的代码。

nmc = 1000
matrices = rand(3,3, nmc);

我需要在生成随机正交矩阵的代码中这样做。

0 个答案:

没有答案