test_rand_special_orthogonal.m

来自「一个用EM算法的源程序」· M 代码 · 共 38 行

M
38
字号
% Tests the random special orthogonal matrix function.n = 10;X = rand_special_orthogonal(n);% Test that all rows and columns have unity magnitude.for col = 1:10,    if abs(norm(X(:,col))-1) > .000001,        error('Found column of non-unity norm')    end    if abs(norm(X(col,:))-1) > .000001,        error('Found row of non-unity norm')    endend% Check that the determinant of the matrix is unityif abs(det(X)-1) > .0001,    error('Matrix does not have unity determinant')end% Check distribution by taking a random vector and seeing where a bunch of% X's take it.n = 2;x = randn(n,1);numpoints = 500;XX = zeros(n,numpoints);for k = 1:numpoints,    X=rand_special_orthogonal(n);    xx = X*x;    XX(:,k) = xx;endif n==2,    plot(XX(1,:),XX(2,:),'ro')endif n==3,plot3(XX(1,:),XX(2,:),XX(3,:),'ro')end

⌨️ 快捷键说明

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