예제 #1
0
        //row operations: multiply a row by a constant, add a multiple of a row to another, swap rows
        public AugmentedMatrix GaussMatrix()
        {
            if (RowSize == 1 && ColumnSize == 2)
            {
                return(this.GenerateClone());                                 //already solved
            }
            //break down into solving two rows
            AugmentedMatrix copy = this.GenerateClone();

            for (int k = 0; k < RowSize; k++)
            {
                for (int i = k + 1; i < RowSize; i++)
                {
                    RationalNumber[] orig = GetRow(i).ToArray <RationalNumber>();
                    for (int j = 0; j < ColumnSize - 1; j++)
                    {
                        RationalNumberRowVector vec = SetToZero(i, k, j);
                        copy.ReplaceRow(k, vec);
                    }
                }
            }
            for (int k = RowSize - 1; k >= 0; k--)
            {
                for (int i = k - 1; i >= 0; i--)
                {
                    RationalNumber[] orig = GetRow(i).ToArray <RationalNumber>();
                    for (int j = ColumnSize - 2; j >= k; j--)
                    {
                        RationalNumberRowVector vec = SetToZero(k, i, j);
                        copy.ReplaceRow(k, vec);
                    }
                }
            }
            return(copy);
        }
예제 #2
0
        public AugmentedMatrix SwapRows(int row1, int row2)
        {
            AugmentedMatrix ret = GenerateClone();

            RationalNumber[] ary1 = GetRow(row1).ToArray <RationalNumber>();
            RationalNumber[] ary2 = GetRow(row2).ToArray <RationalNumber>();
            for (int i = 0; i < ary1.Length; i++)
            {
                ret.Replace(row1, i, ary2[i]);
                ret.Replace(row2, i, ary1[i]);
            }
            return(ret);
        }