public Set ( int column, int row, double value ) : void | ||
column | int | The Column. |
row | int | The Row. |
value | double | The Value. |
Результат | void |
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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."); } }
/// <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); }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
/// <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."); } }
/// <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; }