8 m square matrix with elements of suitable type
10 return zero or value of type determined by types of elements
13 The matrix m has to be square, i.e. of dimension 2 with:
15 matmax(m,1) - matmin(m,1) == matmax(m,2) - matmin(m,2).
17 If the elements of m are numbers (real or complex), det(m)
18 returns the value of the determinant of m.
20 If some or all of the elements of m are not numbers, the algorithm
21 used to evaluate det(m) assumes the definitions of *, unary -, binary -,
22 being zero or nonzero, are consistent with commutative ring structure,
23 and if the m is larger than 2 x 2, division by nonzero elements is
24 consistent with integral-domain structure.
26 If m is a 2 x 2 matrix with elements a, b, c, d, where a tests as
27 nonzero, det(m) is evaluated by
29 det(m) = (a * d) - (c * b).
31 If a tests as zero, det(m) = - ((c * b) - (a * d)) is used.
33 If m is 3 * 3 with elements a, b, c, d, e, f, g, h, i, where a and
34 a * e - d * b test as nonzero, det(m) is evaluated by
36 det(m) = ((a * e - d * b) * (a * i - g * c)
37 - (a * h - g * b) * (a * f - d * c))/a.
40 ; mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23}
41 ; c = config("mode", "frac")
42 ; print det(A), det(A^2), det(A^3), det(A^-1)
43 -78 6084 -474552 -1/78
47 ; define res_test(a) = !ismult(a.r, md)
48 ; define res_sub(a,b) {local obj res v = {(a.r - b.r) % md}; return v;}
49 ; define res_mul(a,b) {local obj res v = {(a.r * b.r) % md}; return v;}
50 ; define res_neg(a) {local obj res v = {(-a.r) % md}; return v;}
51 ; define res(x) {local obj res v = {x % md}; return v;}
53 ; mat A[2,2] = {res(2), res(3), res(5), res(7)}
61 Note that if A had been a 3 x 3 or larger matrix, res_div(a,b) for
62 non-zero b would have had to be defined (assuming at least one
63 division is necessary); for consistent results when md is composite,
64 res_div(a,b) should be defined only when b and md are relatively
65 prime; there is no problem when md is prime.
71 VALUE matdet(MATRIX *m)
74 matdim, matmax, matmin, inverse
76 ## Copyright (C) 1999 Landon Curt Noll
78 ## Calc is open software; you can redistribute it and/or modify it under
79 ## the terms of the version 2.1 of the GNU Lesser General Public License
80 ## as published by the Free Software Foundation.
82 ## Calc is distributed in the hope that it will be useful, but WITHOUT
83 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
84 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
85 ## Public License for more details.
87 ## A copy of version 2.1 of the GNU Lesser General Public License is
88 ## distributed with calc under the filename COPYING-LGPL. You should have
89 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
90 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
92 ## @(#) $Revision: 30.1 $
93 ## @(#) $Id: det,v 30.1 2007/03/16 11:10:42 chongo Exp $
94 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/det,v $
96 ## Under source code control: 1995/11/28 11:17:47
97 ## File existed as early as: 1995
99 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
100 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/