Vector input to eigen value problem

조회 수: 10 (최근 30일)
muhammad imran
muhammad imran 2020년 12월 24일
편집: muhammad imran 2020년 12월 26일
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개)

카테고리

Help CenterFile Exchange에서 LaTeX에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by