Exemple #1
0
        public virtual T JordanDeterminant()
        {
            var field = Fields.getField <T>();

            if (!this.isSquare)
            {
                throw new ArithmeticException("cannot get determinant of non-square matrix");
            }
            var ret = field.one;
            MatrixBuilder <T> builder = new MatrixBuilder <T>(this.to2DArr());

            foreach (int row in range.Range(this.rows))
            {
                int pivotsearcher = row;
                while (pivotsearcher < this.rows && builder[pivotsearcher, row].Equals(field.zero))
                {
                    pivotsearcher++;
                }
                if (pivotsearcher == this.rows)
                {
                    return(field.zero);
                }
                if (pivotsearcher != row)
                {
                    builder.SwapRows(pivotsearcher, row);
                    ret = field.Negate(ret);
                }
                ret = field.multiply(ret, builder[row, row]);
                builder.MultRowByFactor(row, field.Invert(builder[row, row]));
                foreach (int i in range.Range(this.rows).Except(row))
                {
                    builder.AddRowByFactor(row, i, field.Negate(builder[i, row]));
                }
            }
            return(ret);
        }