Ejemplo n.º 1
0
 // ********************************************************************
 // Multiply matrix 'm1' by 'm2' to give result in this
 //
 // Usage:  A.mult (A1, A2); multiply A1 by A2 giving A
 //
 // ********************************************************************
 public Matrix mult(Matrix m1, Matrix m2)
 {
     if (m1.c == m2.r)
     {
         resize(m1.r, m2.c);
         int m1_col = m1.c;
         for (int i = 0; i < r; i++)
         {
             for (int j = 0; j < m2.c; j++)
             {
                 var sum = new SimpleComplex(0.0, 0.0);
                 for (int k = 0; k < m1_col; k++)
                 {
                     sum = SimpleComplex.complexAdd(sum, SimpleComplex.complexMult(m1[i, k], m2[k, j]));
                 }
                 this[i, j] = sum;
             }
         }
         return(this);
     }
     else
     {
         throw new EMatrixSizeError("Incompatible matrix operands to multiply");
     }
 }
Ejemplo n.º 2
0
        // ---------------------------------------------------------------------
        // Add a scalar value to a matrix
        // Usage:
        //   m.add (Pi);
        // ---------------------------------------------------------------------

        public void add(double k)
        {
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c; j++)
                {
                    this[i, j] = SimpleComplex.complexAdd(this[i, j], new SimpleComplex(k, 0.0));
                }
            }
        }
Ejemplo n.º 3
0
        // ---------------------------------------------------------------------
        // Add a scalar value to a matrix and return a new matrix
        // Usage:
        //   Matrix m1 = Matrix.add (m2, Pi);
        // ---------------------------------------------------------------------

        public static Matrix add(Matrix x, double k)
        {
            var result = new Matrix(x.r, x.c);

            for (int i = 0; i < x.r; i++)
            {
                for (int j = 0; j < x.c; j++)
                {
                    result[i, j] = SimpleComplex.complexAdd(x[i, j], new SimpleComplex(k, 0.0));
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        // ---------------------------------------------------------------------
        // Add a matrix to this. this is modified
        // Usage:
        //   m.add (m1)
        // ---------------------------------------------------------------------

        public void add(Matrix x)
        {
            if (sameDimensions(this, x))
            {
                for (int i = 0; i < x.r; i++)
                {
                    for (int j = 0; j < x.c; j++)
                    {
                        this[i, j] = SimpleComplex.complexAdd(this[i, j], x[i, j]);
                    }
                }
            }
            else
            {
                throw new EMatrixException("Matrices must be the same dimension to perform addition");
            }
        }
Ejemplo n.º 5
0
        // Add Methods:

        //  Methods that return a new matrix
        //  m = Matrix.add (m1, m2);
        //  m = Matrix.add (m1, 2.3);

        //  Methods that modify the matrix object
        //  m.add (m1);
        //  m.add (2.3);


        // ---------------------------------------------------------------------
        // Add two matrices together and return the result as a new matrix
        // Usage:
        //   Matrix m3 = Matrix.add (m1, m2);
        // ---------------------------------------------------------------------

        public static Matrix add(Matrix x, Matrix y)
        {
            if (sameDimensions(x, y))
            {
                var result = new Matrix(x.r, x.c);
                for (int i = 0; i <= x.r; i++)
                {
                    for (int j = 0; j <= x.c; j++)
                    {
                        result[i, j] = SimpleComplex.complexAdd(x[i, j], y[i, j]);
                    }
                }
                return(result);
            }
            else
            {
                throw new EMatrixException("Matrices must be the same dimension to perform addition");
            }
        }