示例#1
0
        public virtual Matrix <T> JordanInvert()
        {
            var field = Fields.getField <T>();

            if (!this.isSquare)
            {
                throw new ArithmeticException("cannot invert non-square matrix");
            }
            MatrixBuilder <T> ret = new MatrixBuilder <T>(this.to2DArr().Concat(getIdent(this.rows).to2DArr(), 1));

            foreach (int row in range.Range(this.rows))
            {
                int pivotsearcher = row;
                while (pivotsearcher < this.rows && ret[pivotsearcher, row].Equals(field.zero))
                {
                    pivotsearcher++;
                }
                if (pivotsearcher == this.rows)
                {
                    throw new ArithmeticException("matrix is singular!");
                }
                if (pivotsearcher != row)
                {
                    ret.SwapRows(pivotsearcher, row);
                }
                ret.MultRowByFactor(row, field.Invert(ret[row, row]));
                foreach (int i in range.Range(this.rows).Except(row))
                {
                    ret.AddRowByFactor(row, i, field.Negate(ret[i, row]));
                }
            }
            var m = ret.toMutableMatrix();

            return(new MapMatrix <T>((i, j) => m[i, j + this.rows], this.rows, this.rows));
        }
示例#2
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);
        }