Open in the MATLAB editor: f08ng_example
function f08ng_example fprintf('f08ng example results\n\n'); n = int64(4); ilo = int64(1); ihi = n; a = [ 0.35, 0.45, -0.14, -0.17; 0.09, 0.07, -0.54, 0.35; -0.44, -0.33, -0.03, 0.17; 0.25, -0.32, -0.13, 0.11]; % Reduce A to upper Hessenberg Form A = QHQ^T [H, tau, info] = f08ne( ... ilo, ihi, a); % Form Q [Q, info] = f08nf( ... ilo, ihi, H, tau); % Schur factorize H = Y*T*Y^T job = 'Schur form'; compz = 'No Vectors'; [~, wr, wi, ~, info] = f08pe( ... job, compz, ilo, ihi, H, Q); w = wr + i*wi; disp('Eigenvalues of A'); disp(w); % Calculate eigenvetors of H corresponding to negative real part eigenvalues select = (wr < 0); job = 'Right'; eigsrc = 'QR'; initv = 'No initial vectors'; vl = []; vr = zeros(n,n); [~, ~, ~, VR, m, ifaill, ifailr, info] = ... f08pk( ... job, eigsrc, initv, select, H, wr, wi, vl, vr, n); % Eigenvectors of A = Q*VR side = 'Left'; trans = 'No transpose'; [V, info] = f08ng( ... side, trans, ilo, ihi, H, tau, VR); % Combine columns of V into complex eigenvectors Z j = 0; for k = 1:n if select(k) j = j+1; if (wi(k)==0) % Normalize eigenvector: largest element positive [~,l] = max(abs(V(:,j))); if V(l,j) < 0; V(:,j) = -V(:,j); end Z(:,j) = complex(V(:,j)); else Z(:,j) = V(:,j) + i*V(:,j+1); Z(:,j+1) = V(:,j) - i*V(:,j+1); % Normalize: largest element is real [~,l] = max(abs(real(Z(:,j)))+abs(imag(Z(:,j)))); Z(:,j) = Z(:,j)*conj(Z(l,j))/abs(Z(l,j)); Z(:,j+1) = Z(:,j+1)*conj(Z(l,j+1))/abs(Z(l,j+1)); j = j+1; select(k+1) = false; end end end disp('Eigenvectors corresponding to eigenvalues with negative real part'); disp(Z);
f08ng example results Eigenvalues of A 0.7995 + 0.0000i -0.0994 + 0.4008i -0.0994 - 0.4008i -0.1007 + 0.0000i Eigenvectors corresponding to eigenvalues with negative real part -0.2379 + 0.3134i -0.2379 - 0.3134i 0.1493 + 0.0000i 0.3100 - 0.6430i 0.3100 + 0.6430i 0.3956 + 0.0000i 0.1196 - 0.3795i 0.1196 + 0.3795i 0.7075 + 0.0000i 0.8319 + 0.0000i 0.8319 + 0.0000i 0.8603 + 0.0000i