Output from imleig.sas |
Source
0 Graphs |
---|
NOTE: Capture of log output started.
NOTE: %INCLUDE (level 1) file n:\psy6140\examples\iml\imleig.sas is file n:\psy6140\examples\iml\imleig.sas.
360 +title 'IMLEIG: Eigenvalues and Eigenvectors'; 361 + * ------ ---------------------------- ; 362 +proc iml;
IML Ready
363 + reset print log fuzz fw=5; 364 +*[Johnson and Wichern, EX.2.9],; 365 +A={13 -4 2, -4 13 -2, 2 -2 10};
A 3 rows 3 cols (numeric) 13 -4 2 -4 13 -2 2 -2 10
366 +call eigen(values, vectors, A);
VALUES 3 rows 1 col (numeric) 18 9 9 VECTORS 3 rows 3 cols (numeric) 0.667 0.383 0.64 -0.67 0.69 0.282 0.333 0.615 -0.71
367 +*-- Properties of eigenvalues; 368 +*-- 1. trace(A) = sum of eigenvalues; 369 +r = sum(values);
R 1 row 1 col (numeric) 36
370 +r = sum(vecdiag(A));
R 1 row 1 col (numeric) 36
371 +*-- 2. ssq(A) = ssq(eigenvalues); 372 +print (ssq(A)) '=' (ssq(values));
#TEM1001 #TEM1002 486 = 486
373 +*-- 3. det(A) = product of eigenvalues; 374 +print (det(A)) '=' (values[#]);
#TEM1001 #TEM1002 1458 = 1458
375 +*-- 4. rank a = number non-zero latent values; 376 +r = echelon(A);
R 3 rows 3 cols (numeric) 1 0 0 0 1 0 0 0 1
377 +rank = (((echelon(A)^=0)[,+]) ^=0)[+,];
RANK 1 row 1 col (numeric) 3
378 +rank = sum(values ^= 0);
RANK 1 row 1 col (numeric) 3
379 +*-- 5. eigenvalues of inv(A) = 1/eigenvalues of A, same vectors; 380 +AI = inv(A);
AI 3 rows 3 cols (numeric) 0.086 0.025 -0.01 0.025 0.086 0.012 -0.01 0.012 0.105
381 +call eigen(val, vec, AI);
VAL 3 rows 1 col (numeric) 0.111 0.111 0.056 VEC 3 rows 3 cols (numeric) -0.24 0.707 0.667 0.236 0.707 -0.67 0.943 0 0.333
382 +* similar relation for other powers: roots(A##n) = (roots(A) ## n); 383 +call eigen(val, vec, A*A);
VAL 3 rows 1 col (numeric) 324 81 81 VEC 3 rows 3 cols (numeric) 0.667 0.745 -0.02 -0.67 0.608 0.431 0.333 -0.27 0.902
384 +call eigen(val, vec, A*A*A);
VAL 3 rows 1 col (numeric) 5832 729 729 VEC 3 rows 3 cols (numeric) 0.667 0.745 -0.02 -0.67 0.61 0.428 0.333 -0.27 0.904
386 +*-- SPECTRAL DECOMPOSITION WITH ROOTS AND VECTORS; 387 +A={13 -4 2, -4 13 -2, 2 -2 10};
A 3 rows 3 cols (numeric) 13 -4 2 -4 13 -2 2 -2 10
388 +call eigen(L, V, A);
L 3 rows 1 col (numeric) 18 9 9 V 3 rows 3 cols (numeric) 0.667 0.383 0.64 -0.67 0.69 0.282 0.333 0.615 -0.71
389 +*-- 1. A * V[,I] = L[I] # V[,I]; 390 +r = A * V[,1];
R 3 rows 1 col (numeric) 12 -12 6
391 +r = L[1] # V[,1];
R 3 rows 1 col (numeric) 12 -12 6
392 +print A '*' (V[,1]) '=' (A*V[,1]) '=' (L[1]) '#' (V[,1]);
A #TEM1001 #TEM1003 #TEM1004 #TEM1005 13 -4 2 * 0.667 = 12 = 18 # 0.667 -4 13 -2 -0.67 -12 -0.67 2 -2 10 0.333 6 0.333
393 +r = A * V;
R 3 rows 3 cols (numeric) 12 3.443 5.757 -12 6.209 2.54 6 5.531 -6.43
394 +r = V * diag(L);
R 3 rows 3 cols (numeric) 12 3.443 5.757 -12 6.209 2.54 6 5.531 -6.43
395 +print A '*' V '=' V '*' (diag(L)) ;
A V V #TEM1001 13 -4 2 * 0.667 0.383 0.64 = 0.667 0.383 0.64 * 18 0 0 -4 13 -2 -0.67 0.69 0.282 -0.67 0.69 0.282 0 9 0 2 -2 10 0.333 0.615 -0.71 0.333 0.615 -0.71 0 0 9
396 +* V diagonalizes A: V'AV = diagonal; 397 +r = t(V) * A * V;
R 3 rows 3 cols (numeric) 18 0 0 0 9 0 0 0 9
398 +*-- 2. Eigenvectors are orthogonal and unit length: V'V=I; 399 +r = t(V) * V;
R 3 rows 3 cols (numeric) 1 0 0 0 1 0 0 0 1
400 +* 3. SPECTRAL DECOMPOSITION: A = sum of rank 1 products; 401 +A1 = L[1] # V[,1] * t(V[,1]);
A1 3 rows 3 cols (numeric) 8 -8 4 -8 8 -4 4 -4 2
402 +A2 = L[2] # V[,2] * t(V[,2]);
A2 3 rows 3 cols (numeric) 1.317 2.376 2.116 2.376 4.283 3.816 2.116 3.816 3.399
403 +A3 = L[3] # V[,3] * t(V[,3]);
A3 3 rows 3 cols (numeric) 3.683 1.624 -4.12 1.624 0.717 -1.82 -4.12 -1.82 4.601
404 +r = A1 + A2 + A3;
R 3 rows 3 cols (numeric) 13 -4 2 -4 13 -2 2 -2 10
405 +r = ssq(A);
R 1 row 1 col (numeric) 486
406 +r = ssq(A1) || ssq(A2) || ssq(A3);
R 1 row 3 cols (numeric) 324 81 81
407 +*-- Each root is sum of squares accounted for; 408 +r = L##2;
R 3 rows 1 col (numeric) 324 81 81
409 +*--The first i roots and vectors give a rank i approximation; 410 +r = echelon(A1+A2);
R 3 rows 3 cols (numeric) 1 0 0.895 0 1 0.395 0 0 0
411 +r = ssq(A1+A2);
R 1 row 1 col (numeric) 405
412 +quit;
Exiting IML.
NOTE: The PROCEDURE IML used 0.33 seconds.
413 +
NOTE: %INCLUDE (level 1) ending.