Пример #1
0
        //likely lossy conversion, truncation of decimals
        public SquareIntegerMatrix GetInverse()
        {
            int det = Determinant();

            if (det == 0)
            {
                throw new MatrixTypeMismatchException(); //matrix is not invertible
            }
            SquareIntegerMatrix ret = new SquareIntegerMatrix(Size);

            if (Size == 2)
            {
                for (int i = 0; i < Size; i++)
                {
                    for (int j = 0; j < Size; j++)
                    {
                        ret.Replace(i, j, Get(i, j) / det);
                    }
                }
            }
            else
            {
                //size > 2 TODO:
            }
            return(ret);
        }
Пример #2
0
        //TODO: classify multiplications to have the products be as explicit as possible.
        //im sure theres a better way to do this lol
        public SquareIntegerMatrix Multiply(SquareIntegerMatrix other)
        {
            IntegerMatrix       product = Multiply(other as IntegerMatrix);
            SquareIntegerMatrix ret     = new SquareIntegerMatrix(other.RowSize);

            for (int i = 0; i < RowSize; i++)
            {
                for (int j = 0; j < RowSize; j++)
                {
                    ret.Replace(i, j, product.Get(i, j));
                }
            }
            return(ret);
        }
Пример #3
0
 public SquareIntegerMatrix TrySquareConversion()
 {
     if (IsSquare)
     {
         SquareIntegerMatrix ret = new SquareIntegerMatrix(RowSize);
         for (int i = 0; i < RowSize; i++)
         {
             for (int j = 0; j < RowSize; j++)
             {
                 ret.Replace(i, j, this.Get(i, j));
             }
         }
         return(ret);
     }
     else
     {
         throw new MatrixTypeMismatchException();
     }
 }