-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
132,362 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function [T] = Lanczos(A,n); | ||
%Lancozs Algorithm to find Eigenvalue spectra | ||
%Inputs :A hermitian matrix of the order n | ||
% :n order of the matrix | ||
|
||
T = zeros(n); | ||
|
||
v = rand(n,1); %Random vector | ||
v1 = v/norm(v); % | ||
|
||
t = A*v1; | ||
alpha = v1'*t; | ||
t = t - v1*alpha; | ||
|
||
T(1,1) = alpha; | ||
|
||
for j = 2:n, | ||
|
||
beta = norm(t); | ||
v0 = v1; v1 = t/beta; | ||
|
||
t = A*v1 - v0*beta; | ||
alpha = v1'*t; | ||
t = t - v1*alpha; | ||
|
||
T(j,j-1) = beta; T(j-1,j) = beta; T(j,j) = alpha; | ||
|
||
|
||
end | ||
T | ||
eig(T) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
%Lancozs Algorithm to find Eigenvalue spectra | ||
%Inputs :A matrix of the order n | ||
% :n order of the matrix | ||
%Author:Jishnu Rajendran | ||
%As a part of semester project | ||
% | ||
|
||
|
||
function [T,V,u] = Lanczos(A,n) | ||
|
||
T = zeros(n); %Initailising the T matrix with all | ||
%All entries 0 | ||
V = zeros(n,n); | ||
% if abs(norm(u)-1)<0.001 | ||
% w1=u; | ||
%else | ||
w1 = rand(n,1); %Generating Random vector of norm 1 | ||
w1 = w1/norm(w1); % | ||
u=w1; | ||
|
||
|
||
t = A*w1; | ||
alpha = w1'*t; | ||
t = t - w1*alpha; | ||
|
||
V(:,1) = w1; | ||
T(1,1) = alpha; | ||
|
||
for j = 2:n, | ||
|
||
beta = norm(t); | ||
w0 = w1; w1 = t/beta; | ||
|
||
t = A*w1 - w0*beta; | ||
alpha = w1'*t; | ||
t = t - w1*alpha; | ||
|
||
T(j,j-1) = beta; | ||
T(j-1,j) = beta; | ||
T(j,j) = alpha; | ||
V(:,j) = w1; | ||
[X,~]=eig(T); | ||
if(abs(X(j,n))<0.000001) | ||
break | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
%A=load('input.txt'); | ||
%A=[2 0 1; | ||
% 0 3 0; | ||
% 1 0 2;]; | ||
%A = rand(5,5); | ||
%A=rherm(5) | ||
A | ||
eig(A) | ||
[n,n]=size(A); | ||
|
||
Lanczos(A,n); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
sHH=load('sparse_ham_sz_2.txt'); | ||
%H = diag(ones(20, 1),0) + 0.5*diag(ones(19,1), 1) + 0.5*diag(ones(19,1), -1); | ||
%H(20,1)=1;H(1,20)=1; | ||
%D=[2 0 1; 0 3 0; 1 0 2;]; | ||
%u =[0.171799151874028; 0.751483050929023; 0.636991582033681;]; | ||
|
||
A=spconvert(H); | ||
%save('A_mat.txt','A'); | ||
issparse(A) | ||
g=eig(A); | ||
disp(g); | ||
[~,n]=size(A); | ||
[S,D]=eigs(A); %S is the matrix with the eigenvectors as column | ||
S; | ||
[T,V,u]=Lanczos(A,n); | ||
T; | ||
V; | ||
k=eig(T); | ||
disp(k); | ||
[X,Z]=eig(T); % X is the matrix with the eigenvectors as column | ||
X; | ||
B=eig(T)-eig(A); | ||
disp(B); | ||
disp([g,k]); | ||
disp(u); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function [ A ] = rherm(n) | ||
% Generate a hermitian matrix with random values. | ||
% rherm(n) returns a random hermitian matrix of size n*n | ||
if exist('n')~=1, n=2; end | ||
A = [zeros(1,0),(2*rand(1,1)-1),(2*rand(1,n-1)-1)+(2*rand(1,n-1)-1)*1i;zeros(n-1,n)]; | ||
for i=1:n-1, A = A + [zeros(n-i,n);zeros(1,n-i),(2*rand(1,1)-1),(2*rand(1,i-1)-1)+(2*rand(1,i-1)-1)*1i;zeros(i-1,n)];end | ||
for i=1:n-1, for j=1:n-i, A = A + [zeros(n-i,n);zeros(1,j-1),conj(A(j,n-i+1)),zeros(1,n-j);zeros(i-1,n)];end;end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.