Vector input to eigen value problem

12 次查看(过去 30 天)
I am working on problem that involves a big matrix with its elements that depends on two variables. I am ploting eigen values of this matrix with respect to these two variables. I want to give vectorized input into matrix so that it takes less computation time. I am putting here a prototype matrix problem that mimics our problem. I have commented out the scalar input procdure. The vectorize method is not working.
Any help will be highly appreciated.
clear kx ky k1 k2 Nmax H myfile EigHF Ham P Ha
tic
global Nmax H k1 k2 EigHF
Nmax = 40;
k1 = 0:1:Nmax;
k2 = 0:1:Nmax;
H = zeros(Nmax,Nmax);
EigHF = zeros(length(k1),length(k2), Nmax);
% The scalar input method is commented%%%
% for i = 1:1: length(k1)
% for j = 1:1:length(k2)
% EigHF(i,j,:) = myfile(k1(i),k2(j));
% end
% end
EigHF (k1(:),k2(:),:)= myfile(k1(:),k2(:));
[kx,ky] = meshgrid(k1,k2);
hold on
subplot
for i=1:Nmax
mesh(kx,ky, EigHF(:,:,i))
hold on
end
hold off
toc
function [P] = myfile(xx,yy)
global EigHF k1 k2
EigHF(k1 == xx,k2 == yy,:) = sort(real(eig(Ham(xx,yy))));
P = EigHF(k1 == xx,k2 == yy,:);
end
function [Ha] = Ham(x,y)
global Nmax
H = zeros(Nmax,Nmax);
for i = 1:1:Nmax
for j = 1:1:Nmax
H(i,j) = sin(i*x)*cos(j*y);
end
end
Ha = H;
end

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by