LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
spectd.m
1function [spectrum,projectors,nihil,V,D]=spectd(A,OPT)
2if nargin<2
3 JORDAN=0;
4elseif strcmpi(OPT,'jordan')
5 JORDAN=1;
6else
7 JORDAN=0;
8end
9if JORDAN
10 [V,J]=jordan(A);
11 iV=inv(V);
12 n=length(A);
13 from=1;
14 if issym(A(1,1))
15 spectrum=sym([]);
16 projectors={};
17 nihil={};
18 else
19 spectrum=[];
20 projectors={};
21 nihil={};
22 end
23 for to=1:n
24 if to==n || J(to,to+1)==0 % next is new block
25 spectrum(end+1)=J(from,from);
26 projectors{end+1}=V*subblock(sym(eye(n)),from,to)*iV;
27 nihil{end+1}=V*subblock(diag(ones(1,n-1),1),from,to)*iV;
28 from=to+1;
29 end
30 end
31 D=J;
32else
33 if ~strcmpi(class(A(1,1)),'sym')
34 if ~issparse(A)
35 [V,D]=eig(A);
36 else
37 [V,D]=eigs(A);
38 end
39 spectrum=diag(D);
40 projectors={};
41 else
42 [V,D]=eig(A);
43 spectrum=diag(D);
44 projectors={};
45 i=1:length(A);
46 end
47 i=1:length(A);
48 spectrum=spectrum(i);
49 iV=inv(V);
50 for k=i(:)'
51 projectors{end+1}=V(:,k)*iV(k,:);
52 end
53 nihil={};
54end
55spectrum=reshape(spectrum,1,length(spectrum));
56
57 function X=subblock(X,from,to)
58 X(1:(from-1),:)=0;
59 X(:,1:(from-1))=0;
60 X((to+1):end,:)=0;
61 X(:,(to+1):end)=0;
62 end
63
64end