Set() public method

Sets a value of the element.
public Set ( int column, int row, double value ) : void
column int The Column.
row int The Row.
value double The Value.
return void
示例#1
0
        /// <summary>
        /// Resizes the matrix.
        /// </summary>
        /// <param name="columns">The Columns.</param>
        /// <param name="rows">The Rows.</param>
        /// <returns>Matrix</returns>
        public Matrix Resize(int columns, int rows)
        {
            var result = new Matrix(columns, rows);

            for (int y = 0; y <= rows - 1; y++)
            {
                for (int x = 0; x <= columns - 1; x++)
                {
                    if (x <= Columns - 1 && y <= Rows - 1)
                    {
                        result.Set(x, y, Get(x, y));
                    }
                    else
                    {
                        result.Set(x, y, 0);
                    }
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Transposes the matrix.
        /// </summary>
        /// <returns>Matrix</returns>
        public Matrix Transpose()
        {
            var result = new Matrix(Rows, Columns);

            for (int y = 0; y <= Rows - 1; y++)
            {
                for (int x = 0; x <= Columns - 1; x++)
                {
                    result.Set(y, x, Get(x, y));
                }
            }
            return(result);
        }
示例#3
0
        /// <summary>
        /// Pow the matrix.
        /// </summary>
        /// <param name="exponent">The Exponent.</param>
        /// <returns>Matrix</returns>
        public Matrix Pow(double exponent)
        {
            var result = new Matrix(Columns, Rows);

            for (int y = 0; y <= Rows - 1; y++)
            {
                for (int x = 0; x <= Columns - 1; x++)
                {
                    result.Set(x, y, MathHelper.Pow((float)Get(x, y), (float)exponent));
                }
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// Scalarmultiply with a matrix.
        /// </summary>
        /// <param name="a">The Matrix.</param>
        /// <param name="scalar">The Scalar</param>
        /// <returns>Matrix</returns>
        public static Matrix operator *(double scalar, Matrix a)
        {
            CheckForNull(a);
            var result = new Matrix(a.Columns, a.Rows);

            for (int y = 0; y <= a.Rows - 1; y++)
            {
                for (int x = 0; x <= a.Columns - 1; x++)
                {
                    result.Set(x, y, a.Get(x, y) * scalar);
                }
            }

            return(result);
        }
示例#5
0
 /// <summary>
 /// Copys the current Matrix to another matrix.
 /// </summary>
 /// <param name="matrix">The Matrix.</param>
 public void CopyTo(Matrix matrix)
 {
     if (Columns == matrix.Columns && Rows == matrix.Rows)
     {
         for (int y = 0; y <= Rows - 1; y++)
         {
             for (int x = 0; x <= Columns - 1; x++)
             {
                 matrix.Set(x, y, Get(x, y));
             }
         }
     }
     else
     {
         throw new ArgumentException("The matrices needs to have the same size.");
     }
 }
示例#6
0
        /// <summary>
        /// Divide two matrices.
        /// </summary>
        /// <param name="a">The first Matrix.</param>
        /// <param name="b">The second Matrix.</param>
        /// <returns>Matrix</returns>
        public static Matrix operator /(Matrix a, Matrix b)
        {
            CheckForNull(a, b);
            if (a.Columns != b.Columns || a.Rows != b.Rows)
            {
                throw new InvalidOperationException("The two matrices needs to have the same size.");
            }

            var result = new Matrix(a.Columns, a.Rows);

            for (int y = 0; y <= a.Rows - 1; y++)
            {
                for (int x = 0; x <= a.Columns - 1; x++)
                {
                    result.Set(x, y, a.Get(x, y) / b.Get(x, y));
                }
            }

            return(result);
        }
示例#7
0
        /// <summary>
        /// Multiplys two matrices.
        /// </summary>
        /// <param name="a">The first Matrix.</param>
        /// <param name="b">The second Matrix.</param>
        /// <returns>Matrix</returns>
        public static Matrix operator *(Matrix a, Matrix b)
        {
            CheckForNull(a, b);
            if (a.Columns != b.Columns || a.Rows != b.Rows)
                throw new InvalidOperationException("The two matrices needs to have the same size.");

            var result = new Matrix(a.Columns, a.Rows);

            for (int y = 0; y <= a.Rows - 1; y++)
            {
                for (int x = 0; x <= a.Columns - 1; x++)
                {
                    result.Set(x, y, a.Get(x, y)*b.Get(x, y));
                }
            }

            return result;
        }
示例#8
0
 /// <summary>
 /// Transposes the matrix.
 /// </summary>
 /// <returns>Matrix</returns>
 public Matrix Transpose()
 {
     var result = new Matrix(Rows, Columns);
     for (int y = 0; y <= Rows - 1; y++)
     {
         for (int x = 0; x <= Columns - 1; x++)
         {
             result.Set(y, x, Get(x, y));
         }
     }
     return result;
 }
示例#9
0
        /// <summary>
        /// Resizes the matrix.
        /// </summary>
        /// <param name="columns">The Columns.</param>
        /// <param name="rows">The Rows.</param>
        /// <returns>Matrix</returns>
        public Matrix Resize(int columns, int rows)
        {
            var result = new Matrix(columns, rows);

            for (int y = 0; y <= rows - 1; y++)
            {
                for (int x = 0; x <= columns - 1; x++)
                {
                    if (x <= Columns - 1 && y <= Rows - 1)
                    {
                        result.Set(x, y, Get(x, y));
                    }
                    else
                    {
                        result.Set(x, y, 0);
                    }
                }
            }

            return result;
        }
示例#10
0
 /// <summary>
 /// Pow the matrix.
 /// </summary>
 /// <param name="exponent">The Exponent.</param>
 /// <returns>Matrix</returns>
 public Matrix Pow(double exponent)
 {
     var result = new Matrix(Columns, Rows);
     for (int y = 0; y <= Rows - 1; y++)
     {
         for (int x = 0; x <= Columns - 1; x++)
         {
             result.Set(x, y, MathHelper.Pow((float) Get(x, y), (float) exponent));
         }
     }
     return result;
 }
示例#11
0
 /// <summary>
 /// Copys the current Matrix to another matrix.
 /// </summary>
 /// <param name="matrix">The Matrix.</param>
 public void CopyTo(Matrix matrix)
 {
     if (Columns == matrix.Columns && Rows == matrix.Rows)
     {
         for (int y = 0; y <= Rows - 1; y++)
         {
             for (int x = 0; x <= Columns - 1; x++)
             {
                 matrix.Set(x, y, Get(x, y));
             }
         }
     }
     else
     {
         throw new ArgumentException("The matrices needs to have the same size.");
     }
 }
示例#12
0
        /// <summary>
        /// Scalarmultiply with a matrix.
        /// </summary>
        /// <param name="a">The Matrix.</param>
        /// <param name="scalar">The Scalar</param>
        /// <returns>Matrix</returns>
        public static Matrix operator *(double scalar, Matrix a)
        {
            CheckForNull(a);
            var result = new Matrix(a.Columns, a.Rows);

            for (int y = 0; y <= a.Rows - 1; y++)
            {
                for (int x = 0; x <= a.Columns - 1; x++)
                {
                    result.Set(x, y, a.Get(x, y)*scalar);
                }
            }

            return result;
        }