/// <summary> /// Initializes a square <see cref="DiagonalMatrix"/> with all zero's except for ones on the diagonal. /// </summary> /// <param name="order">the size of the square matrix.</param> /// <returns>A diagonal identity matrix.</returns> /// <exception cref="ArgumentException"> /// If <paramref name="order"/> is less than one. /// </exception> public static DiagonalMatrix Identity(int order) { var m = new DiagonalMatrix(order); for (var i = 0; i < order; i++) { m._data[i] = 1.0f; } return(m); }
/// <summary> /// Adds another matrix to this matrix. /// </summary> /// <param name="other">The matrix to add to this matrix.</param> /// <returns>The result of the addition.</returns> /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception> public override Matrix<Complex32> Add(Matrix<Complex32> other) { if (other == null) { throw new ArgumentNullException("other"); } if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); } Matrix<Complex32> result; if (other is DiagonalMatrix) { result = new DiagonalMatrix(RowCount, ColumnCount); } else { result = new DenseMatrix(RowCount, ColumnCount); } Add(other, result); return result; }
/// <summary> /// Initializes a square <see cref="DiagonalMatrix"/> with all zero's except for ones on the diagonal. /// </summary> /// <param name="order">the size of the square matrix.</param> /// <returns>A diagonal identity matrix.</returns> /// <exception cref="ArgumentException"> /// If <paramref name="order"/> is less than one. /// </exception> public static DiagonalMatrix Identity(int order) { var m = new DiagonalMatrix(order); for (var i = 0; i < order; i++) { m.Data[i] = 1.0f; } return m; }
/// <summary> /// Returns the transpose of this matrix. /// </summary> /// <returns>The transpose of this matrix.</returns> public override Matrix<Complex32> Transpose() { var ret = new DiagonalMatrix(ColumnCount, RowCount); Array.Copy(Data, ret.Data, Data.Length); return ret; }
/// <summary> /// Subtracts another matrix from this matrix. /// </summary> /// <param name="other">The matrix to subtract.</param> /// <returns>The result of the subtraction.</returns> /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception> public override Matrix<Complex32> Subtract(Matrix<Complex32> other) { if (other == null) { throw new ArgumentNullException("other"); } if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, "other"); } Matrix<Complex32> result; if (other is DiagonalMatrix) { result = new DiagonalMatrix(RowCount, ColumnCount); } else { result = new DenseMatrix(RowCount, ColumnCount); } Subtract(other, result); return result; }
public void MatrixFrom1DArrayIsReference() { var data = new[] {new Complex32(1.0f, 1), new Complex32(2.0f, 1), new Complex32(3.0f, 1), new Complex32(4.0f, 1), new Complex32(5.0f, 1)}; var matrix = new DiagonalMatrix(5, 5, data); matrix[0, 0] = new Complex32(10.0f, 1); Assert.AreEqual(new Complex32(10.0f, 1), data[0]); }
public void CanCreateMatrixWithUniformValues() { var matrix = new DiagonalMatrix(10, 10, new Complex32(10.0f, 1)); for (var i = 0; i < matrix.RowCount; i++) { Assert.AreEqual(matrix[i, i], new Complex32(10.0f, 1)); } }