How I can optimize my code to run faster?
3 views (last 30 days)
Show older comments
Hi everyone,
I am trying to generate a 1000x1000 Gaussian Unitary Matrix (i.e. the diagonal elements are real Gaussian, the upper diagonal elements are complex, where real and imaginary parts are also Gaussian, lower diagonals are just conjugate transpose of upper diagonal elements). And then plot histogram of max eigenvalue of each 100000 realizations.
m=100000;
n=1000;
e1 = []; % Initialize array for eigenvalues
for j=1:m
inputData = rand(n,n); %real part
gaussMatrixReal = random('normal',0,1,size(inputData));
inputData = rand(n,n); %complex part
gaussMatrixComplex = random('normal',0,1,size(inputData));
U0 = diag(diag(gaussMatrixReal));
U1 = triu(gaussMatrixReal, 1);
U2 = triu(gaussMatrixComplex, 1);
H=U0+U1+i*U2+(U1+i*U2)';
e_1(1:n)=eig(H*(1/sqrt(n)));
e1(end+1)=max(e_1);
end
histogram(e1,'Normalization','probability')
Can you please suggest how I can optimize my code? it is running very slow, I need to repeat this code many times changing some variables. Thank you!
0 Comments
Answers (0)
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!