Search code examples
matlaborthogonal

How to generate mean-preserving orthonormal matrix in MATLAB?


I want to generate random mean-preserving orthonormal matrix A in MATLAB, such that :

A*trans(A) = I, && A*1=1 (1 is the vector in which all arrays equal 1)

I would appreciate any suggestions.


Solution

  • I found the answer here: http://mathforum.org/kb/message.jspa?messageID=4575590

    They proposed the following function:

    function [U] = genU(m)
    V1 = ones(m, 1) / sqrt(m);
    [V, L] = svd(V1);
    [Rm1, tmp] = qr(randn(m - 1, m - 1));
    U = V * blkdiag(1, Rm1) * V';
    

    Where m is the desired dimension.