예제 #1
0
        public override RingElement Multiply(RingElement el)
        {
            Matrix <T> B = el as Matrix <T>;

            if (B == null)
            {
                throw new Exception("Ring element cannot be cast as Matrix!");
            }
            if (N != B.M)
            {
                throw new Exception("Invalid dimensions for matrix multiplication!");
            }
            T[][] newElements = new T[M][];
            for (int i = 0; i < M; i++)
            {
                newElements[i] = new T[B.N];
                for (int j = 0; j < B.N; j++)
                {
                    RingElement sum = elements[0][0].Zero();
                    for (int k = 0; k < N; k++)
                    {
                        sum += elements[i][k] * B.GetElement(k, j);
                    }
                    newElements[i][j] = (T)sum;
                }
            }
            return(new Matrix <T>(newElements));
        }
예제 #2
0
        public override bool Equals(RingElement el)
        {
            Rational q = el as Rational;

            if (q == null)
            {
                throw new Exception("RingElement cannot be cast as Rational!");
            }
            return(Numerator == q.Numerator && Denominator == q.Denominator);
        }
예제 #3
0
        public override RingElement Multiply(RingElement el)
        {
            Rational q = el as Rational;

            if (q == null)
            {
                throw new Exception("RingElement cannot be cast as Rational!");
            }
            return(new Rational(Numerator * q.Numerator, Denominator * q.Denominator));
        }
예제 #4
0
        public override RingElement Add(RingElement el)
        {
            Matrix <T> B = el as Matrix <T>;

            if (B == null)
            {
                throw new Exception("Ring element cannot be cast as Matrix!");
            }
            if (B.M != M || B.N != N)
            {
                throw new Exception("Invalid dimensions for matrix addition!");
            }
            T[][] newElements = new T[M][];
            for (int i = 0; i < M; i++)
            {
                newElements[i] = new T[N];
                for (int j = 0; j < N; j++)
                {
                    newElements[i][j] = (T)(elements[i][j] + B.GetElement(i, j));
                }
            }
            return(new Matrix <T>(newElements));
        }
예제 #5
0
 public override bool Equals(RingElement el)
 {
     return(true);
 }