Eigenvalues of a large Matrix

I have to plot the one of the eigenvalues of a large matirx in the following. The matrix is 20*20 dim. Numerically I have to get the eigenvalues and plot that. But the following code is not giving any plot. I have tried to plot it usnig ''For loop'' as normal plot is taking extremely huge time. But using '' for loop'' the plot is empty. Pl somebody help me to solve the long run time case here. Pl see below for my code.
clc;clear
syms x
a=1.0;
b=1.0;
n=20;
I1=eye(n);
I2=eye(2);
matdimension= (n-1);
tempvector = 0:1:matdimension;
tempvector = sqrt(tempvector);
tempmatrix = diag(tempvector);
crea= circshift(tempmatrix,-1);
anni = crea';
sc=(crea).^2;
sanni=(anni).^2;
num=crea*anni;
%creation = circshift(diag(sqrt(0:1:mat_dim)),-1)
sigx=[0,1;1,0];
sigz=[1,0;0,-1];
for x=0.0001:0.1:1.1 %% I need to plot u with x. But normally it is taking huge time as if never ending in the sysmbolic form of x.
f= a.*kron(num,I2) +(b./2).* kron(I1,sigz)+ x.*kron(sigx,(crea+anni));
[~,v]=eig(f);
u=v(1,1);
plot(x,u,'r')
end

 Respuesta aceptada

KSSV
KSSV el 26 de Mayo de 2020
Editada: KSSV el 26 de Mayo de 2020

0 votos

clc; clear all ;
clc;clear
a=1.0;
b=1.0;
n=20;
I1=eye(n);
I2=eye(2);
matdimension= (n-1);
tempvector = 0:1:matdimension;
tempvector = sqrt(tempvector);
tempmatrix = diag(tempvector);
crea= circshift(tempmatrix,-1);
anni = crea';
sc=(crea).^2;
sanni=(anni).^2;
num=crea*anni;
%creation = circshift(diag(sqrt(0:1:mat_dim)),-1)
sigx=[0,1;1,0];
sigz=[1,0;0,-1];
figure
hold on
for x=0.0001:0.1:1.1 %% I need to plot u with x. But normally it is taking huge time as if never ending in the sysmbolic form of x.
f= a.*kron(num,I2) +(b./2).* kron(I1,sigz)+ x.*kron(sigx,(crea+anni));
[~,v]=eig(f);
u=v(1,1);
plot(x,u,'*r')
end
OR
clc; clear all ;
clc;clear
a=1.0;
b=1.0;
n=20;
I1=eye(n);
I2=eye(2);
matdimension= (n-1);
tempvector = 0:1:matdimension;
tempvector = sqrt(tempvector);
tempmatrix = diag(tempvector);
crea= circshift(tempmatrix,-1);
anni = crea';
sc=(crea).^2;
sanni=(anni).^2;
num=crea*anni;
%creation = circshift(diag(sqrt(0:1:mat_dim)),-1)
sigx=[0,1;1,0];
sigz=[1,0;0,-1];
x=0.0001:0.1:1.1 ;
u = zeros(size(x)) ;
for i = 1:length(x) %% I need to plot u with x. But normally it is taking huge time as if never ending in the sysmbolic form of x.
f= a.*kron(num,I2) +(b./2).* kron(I1,sigz)+ x(i).*kron(sigx,(crea+anni));
[~,v]=eig(f);
u(i)=v(1,1);
end
plot(x,u)

5 comentarios

AVM
AVM el 26 de Mayo de 2020
@Kssv: Thanks for your reply. It's working nicely. I would like to plot another two eigenvalues in same plot e.g. P(2,2) and Q(3,3). Is it possible to run inside the same '' for loop'? Pl help me.
KSSV
KSSV el 26 de Mayo de 2020
It should be.....you try out and see..if not post the code here. Thanks is acceptng the asnwer.
AVM
AVM el 26 de Mayo de 2020
@KSSV: Why in your first example only star(*) or dot(.) in plot is vissible? No other style e.g. solid line or dashed line is not giving any graph.
KSSV
KSSV el 26 de Mayo de 2020
If you plot a single point...you should use a marker... ., ^ , etc,
AVM
AVM el 26 de Mayo de 2020
Thanks for your information.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear Algebra en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

AVM
el 26 de Mayo de 2020

Comentada:

AVM
el 26 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by