Output from imldet2.sas |
Source
0 Graphs |
---|
NOTE: Capture of log output started.
NOTE: %INCLUDE (level 1) file n:\psy6140\examples\iml\imldet2.sas is file n:\psy6140\examples\iml\imldet2.sas.
305 +title 'IMLDET2: Evaluation of determinants'; 306 +proc iml;
IML Ready
307 + reset print log; 308 + 309 + *--define a function module to compute cofactor; 310 +start cofactor(A,i,j); 311 + reset noprint; 312 + size = nrow(A); 312 + *size of matrix; 313 + rows = loc( (1:size) ^= i ); 313 + *delete row i; 314 + cols = loc( (1:size) ^= j ); 314 + *delete col j; 315 + minor = det( A[rows,cols] ); 316 + reset print; 317 + return ( ((-1)##(i+j)) # minor ); 318 +finish;
NOTE: Module COFACTOR defined.
319 + 320 + *-- 1. det by cofactor expansion; 321 + A ={4 2 1, 5 6 7, 1 0 3};
A 3 rows 3 cols (numeric) 4 2 1 5 6 7 1 0 3
322 + r = det(A);
R 1 row 1 col (numeric) 50
323 + *-- cofactors of row 1 elements; 324 + print (cofactor(A,1,1)) (A[{2 3},{2 3}]);
#TEM1001 #TEM1002 18 6 7 0 3
325 + print (cofactor(A,1,2)) (A[{2 3},{1 3}]);
#TEM1001 #TEM1002 -8 5 7 1 3
326 + print (cofactor(A,1,3)) (A[{2 3},{1 2}]);
#TEM1001 #TEM1002 -6 5 6 1 0
327 + *-- det = product of row with cofactors; 328 + r = A[1,] * {18, -8, -6};
R 1 row 1 col (numeric) 50
329 + 330 + *-- 2. det by Gaussian elimination (pivoting); 331 + * [cf. Green and Carroll, table 2.2]; 332 + M = {2 3 1 2, 4 2 3 4, 1 4 2 2, 3 1 0 1};
M 4 rows 4 cols (numeric) 2 3 1 2 4 2 3 4 1 4 2 2 3 1 0 1
333 + d = det(M);
D 1 row 1 col (numeric) 15
334 + 335 + *-- pivot on m[1,1] -> det = product of pivots; 336 + D=M[1,1];
D 1 row 1 col (numeric) 2
337 + 338 + *-- Reduce row, col 1 to 0; 339 + M[1,] = M[1,] / M[1,1];
M 4 rows 4 cols (numeric) 1 1.5 0.5 1 4 2 3 4 1 4 2 2 3 1 0 1
340 + M = M - M[,1] * M[1,];
M 4 rows 4 cols (numeric) 0 0 0 0 0 -4 1 0 0 2.5 1.5 1 0 -3.5 -1.5 -2
341 + *-- Drop first row and column; 342 + M = M[{2 3 4},{2 3 4}];
M 3 rows 3 cols (numeric) -4 1 0 2.5 1.5 1 -3.5 -1.5 -2
343 + *-- Accumulate product of pivots; 344 + D = D # M[1,1];
D 1 row 1 col (numeric) -8
345 + 346 + *--Repeat, reducing new row, col 1 to 0; 347 + M[1,] = M[1,] / M[1,1];
M 3 rows 3 cols (numeric) 1 -0.25 0 2.5 1.5 1 -3.5 -1.5 -2
348 + M = M - M[,1] * M[1,];
M 3 rows 3 cols (numeric) 0 0 0 0 2.125 1 0 -2.375 -2
349 + M = M[{2 3},{2 3}];
M 2 rows 2 cols (numeric) 2.125 1 -2.375 -2
350 + D = D # M[1,1];
D 1 row 1 col (numeric) -17
351 + 352 + *--Repeat once more. d = det(m); 353 + M[1,] = M[1,] / M[1,1];
M 2 rows 2 cols (numeric) 1 0.4705882 -2.375 -2
354 + M = M - M[,1] * M[1,];
M 2 rows 2 cols (numeric) 0 0 0 -0.882353
355 + M = M[2,2];
M 1 row 1 col (numeric) -0.882353
356 + D = D # M[1,1];
D 1 row 1 col (numeric) 15
357 +quit;
Exiting IML.
NOTE: The PROCEDURE IML used 0.22 seconds.
358 +
NOTE: %INCLUDE (level 1) ending.