How to generate a random complex unitary matrix whose columns each sum up to 1

34 Ansichten (letzte 30 Tage)
Hello everyone,
basically the problem is exactly what is stated in the title. I want to create an unitary (2D) matrix of random complex numbers, such that the elements of each column of this matrix sum up to exactly 1. Is there any way to do this? As long as it's still reasonable, computation speed and/or memory usage are not that important.
Thank you to everyone trying to help!

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 22 Nov. 2020
Bearbeitet: David Goodmanson am 4 Dez. 2020
MODIFIED to replace previous random function
Hi Michael,
here is one way. It's based on the idea that if the unitary matrix U is nxn, and onz = [1 1 1 1 1 1... ] (length n), then the sum-of-each-column condition is
[1 1 1 1 1 1... ]*U = [1 1 1 1 1 1... ]
so
n = 5;
onz = ones(1,n);
onzc = onz'; % column vector
na = null(onzc');
% construct an (n-1)x(n-1) unitary matrix by employing random numbers
% uniformly distributed on {-1, 1} x {-i, i}
h = 2*(rand(n-1,n-1) + i*rand(n-1,n-1)) -(1+i);
% method 1
[u, ~] = qr(h);
% method 2 (slower)
% [u, ~] = eig(h+h');
% construct the result
U = na*u*na' + (1/n)*onzc*onzc';
% checks, all of these should be small
U'*U -eye(size(U))
U*U' -eye(size(U))
onz*U - onz
onz*U' - onz % U' works too
  18 Kommentare
Bruno Luong
Bruno Luong am 8 Nov. 2024
Bearbeitet: Bruno Luong am 8 Nov. 2024
Hi @David Goodmanson if you are stll reading. Pusing a little bit further the test, I think RAND with EIG does actually not generate uniform Unitary matrices, as you can see in this graph
obtained from this code (warning it takes relatively long to run)
close all
clearvars
% Generate uniform randomly p Orhogonal/Hermitian matrix in R^n
p = 1e7;
n = 3;
rfun = {@(varargin) randn(varargin{:}), ...
@(varargin) 2*rand(varargin{:})-1 };
for i = 1:length(rfun)
randmethod = rfun{i};
U=randmethod(n,n,p);
% David EIG
U = U + permute(conj(U),[2 1 3]);
for k=1:p
[U(:,:,k),~]=eig(U(:,:,k));
end
% random phase
rsign = 2*(rand(1,1,p)>0.5)-1;
rsign = repmat(rsign,[n,1,1]);
U = U.*rsign;
% Check for n=2 or 3
U1=reshape(U(:,1,:),[n p]);
x = real(U1(1,:));
y = real(U1(2,:));
tt = atan2(y,x);
ax = subplot(1,2,i);
histogram(ax, tt,100)
if i == 1
title(ax,'randn')
else
title(ax,'rand')
end
drawnow
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by