Linear Algebra and the C Language/a0og


E1 b1r1 + E2 b2r2 + E3 b3r3 = A

Copy/Paste into the octave window
% A property of spectral decomposition:
%
%       E1 V1 V1' +  E2 V2 V2' + E3 V3 V3' = A
%       E1 b1 r1  +  E2 b2 r2  + E3 b3 r3  = A
%
% V (b) : The columns of the eigenvectors of A
% V'(r) : The rows of the eigenvectors of the inverse of A
%         (Here the transpose: see the first example)
%
%    E : The eigenvalues of A.
%
% V1V1' (b1r1) is obtained by multiplying the first column of the eigenvector
%              of A by the first row of the eigenvector of the inverse of A


clear, clc

A = round(10*randn(3));    %% A matrix 3x3
A = A'*A                   %% A symetric matrix

% Eigenvectors, Eigenvalues
[Evectors,Evalues] = eigs(A);

V1 = Evectors(:,1);
V2 = Evectors(:,2);
V3 = Evectors(:,3);

Evalues = diag([Evalues]);

E1 = Evalues(1);
E2 = Evalues(2);
E3 = Evalues(3);

E1b1r1 = E1.*V1*V1';
E2b2r2 = E2.*V2*V2';
E3b3r3 = E3.*V3*V3';

A = E1b1r1 + E2b2r2 + E3b3r3

%%