Circulate Matrix to perform eigenvectors
1 次查看(过去 30 天)
显示 更早的评论
function [A] = circ (x)
% function [A] = circ(x)
%
if nargin ~= 1; error("Only one input argument !"); return; end
isVector = (( ismatrix(x)) && (( size(x ,1) == 1) || (size(x ,2) == 1)));
if ~ isVector ; error("x is not a vector !"); return; end
if size(x ,1) < size(x ,2); x=x ; end % make a column vector
len_x = max(size(x )); % length of the vector
A = zeros( len_x ); % init matrix A
for i = 0:( len_x -1)
ind = mod ((1: len_x )-i -1, len_x )+1; % index order
A(:,i +1)= x( ind ); % write the rows of x in the order of ind
end %for
tol =1e8;
% (a)
xind =(1:4);
x = xind .*( -1).^ xind ;
A = circ(x); % create circulant matrix A
% (b)
[W, lambda ] = eig(A);
dlambda = diag( lambda );
W = round(W* tol )/ tol;
% (c)
% these are equal
inv(W)
% (d)
y =[1:4];
round(A*y*tol)/ tol;
% (e)
round(W* lambda *W*y * tol)/ tol;
% (f)
xind = [1:100];
x = xind .*( -1).^ xind ;
B = circ (x); % create circulant matrix B
% (g)
% right
twelfth_smallest_ind =100 -12+1;
[RW , Rlambda ] = eig(B); % RW is right eigenvectors
RW=round(RW* tol )/ tol ;
dRlambda = diag( Rlambda );
dRlambda_abs = abs( dRlambda ); % magnitude of eigenvalues
[ dRlambda_abs_sort , dRlambda_abs_ind ] = sortrows ( dRlambda_abs );
dRlambda_abs_sort = flipud( dRlambda_abs_sort );
dRlambda_abs_ind = flipud( dRlambda_abs_ind );
[dRlambda_abs_sort ( twelfth_smallest_ind ), dRlambda_abs_ind ( twelfth_smallest_ind )] % 12th smallest eigenvalue
% 50.9016074095522
R12_ind = dRlambda_abs_ind (( dRlambda_abs_sort == dRlambda_abs_sort ( twelfth_smallest_ind ))); % indicies of 12th smallest eigenvalues
Revec_12 = RW (:, R12_ind );
% left
[LW , Llambda ] = eig(B); LW = conj(LW ); % LW is left eigenvectors
LW=round(LW* tol )/ tol ;
dLlambda = diag( Llambda );
dLlambda_abs = abs( dLlambda ); % magnitude of eigenvalues
[ dLlambda_abs_sort , dLlambda_abs_ind ] = sortrows ( dLlambda_abs );
dLlambda_abs_sort = flipud( dLlambda_abs_sort );
dLlambda_abs_ind = flipud( dLlambda_abs_ind );
[ dLlambda_abs_sort ( twelfth_smallest_ind ), dLlambda_abs_ind ( twelfth_smallest_ind )] % 12th smallest eigenvalue
% 50.9016074095521 86
L12_ind = dLlambda_abs_ind (find( dLlambda_abs_sort == dLlambda_abs_sort ( twelfth_smallest_ind ))); % indicies of 12th smallest eigenvalues
Levec_12 = LW (:, L12_ind );
% plots
subplot(4 ,2 ,1);plot(xind ,real( Levec_12 (: ,1))); title ("Real Left Eigenvector 1");
subplot(4 ,2 ,3);plot(xind ,imag( Levec_12 (: ,1))); title ("Imag Left Eigenvector 1");
subplot(4 ,2 ,5);plot(xind ,real( Levec_12 (: ,2))); title ("Real Left Eigenvector 2");
subplot(4 ,2 ,7);plot(xind ,imag( Levec_12 (: ,2))); title ("Imag Left Eigenvector 2");
subplot(4 ,2 ,2);plot(xind ,real( Revec_12 (: ,1))); title ("Real Right Eigenvector 1");
subplot(4 ,2 ,4);plot(xind ,imag( Revec_12 (: ,1))); title ("Imag Right Eigenvector 1");
subplot(4 ,2 ,6);plot(xind ,real( Revec_12 (: ,2))); title ("Real Right Eigenvector 2");
subplot(4 ,2 ,8);plot(xind ,imag( Revec_12 (: ,2))); title ("Imag Right Eigenvector 2");
plot_name = strcat ("gpcshw04 -3 indy . eps ");
print(gcf, "-depsc2 ", plot_name );
cl f ;plot(xind ,[real( Levec_12 (: ,1)) ,imag( Levec_12 (: ,1))] ,real( Levec_12 (: ,2)) ,imag( Levec_12 (: ,2)) ,real( Revec_12 (: ,1)) ,imag( Revec_12 (: ,1))); title ("All Eigenvectors ");
plot_name == strcat ;"gpcshw04 -3 all . eps ";
print(gcf, "-depsc2 ", plot_name );
I have this code and I need to generate these:
But somrthing in the code is not correct :(
could check my code please? Thanks in advance
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!