# To compute the determinant of a k by k matrix m. k > 0 The matrix is corrupted. # MODE R = REAL; PROC det = (REF [,]R m)R: (INT k = 1 UPB m; (k /= 2 UPB m | print("not square"); GOTO hell); (k = 1 | m[1,1] | FOR j TO k DO (m[j,1] /= 0.0 | (j /= 1 | FOR n TO k DO R t = m[j, n]; m[j, n] := m[1, n]; m[1, n] := -t OD); GOTO zz) OD; 0 EXIT zz: ( R t = 1.0 / m[1,1]; FOR i FROM 2 TO k DO REF []R q = m[i,]; R a = t*q[1]; FOR r FROM 2 TO k DO q[r] -:= a*m[1, r] OD OD; m[1,1] * det(m[2:k, 2:k])))); # To test: # PROC t = ([,]R m)VOID: (INT k = 1UPB m; ([k,k]R z; FOR i TO k DO FOR j TO k DO z[i,j] := m[j,i] OD OD; print((det(LOC [k,k]R := m), " ", det(z), newline)))); t(((1, 0), (0, 1))); #1# t(((1, 0, 0), (0, 1, 0), (0, 0, 1))); #1# t(((2, 3), (5, 4))); #-7# t(((0, 1, 0), (1, 0, 0), (0, 0, 1))); #-1# t(((3.3, 5.6, 4.8, 4.3), (5.6, 4.2, 6.7, 5.2), (7.6, 5.3, 6.6, 4.3), (2.6, 4.8, 4.9, 9.6))); #206.704# t(((0, 2, 3), (0, 3, 6), (0, 5, 2))); #0# hell: SKIP