/// <summary> /// Outer product of two vectors; Sets <i>A[i,j] = x[i] * y[j]</i>. /// </summary> /// <param name="x">the first source vector.</param> /// <param name="y">the second source vector.</param> /// <param name="A">the matrix to hold the resultsd Set this parameter to <i>null</i> to indicate that a new result matrix shall be constructed.</param> /// <returns>A (for convenience only).</returns> public static DoubleMatrix2D MultOuter(DoubleMatrix1D x, DoubleMatrix1D y, DoubleMatrix2D A) { int rows = x.Size; int columns = y.Size; if (A == null) { A = x.Like2D(rows, columns); } if (A.Rows != rows || A.Columns != columns) { throw new ArgumentException(); } for (int row = rows; --row >= 0;) { A.ViewRow(row).Assign(y); } for (int column = columns; --column >= 0;) { A.ViewColumn(column).Assign(x, BinaryFunctions.Mult); } return(A); }
/// <summary> /// Returns a string representation of the given matrix. /// </summary> /// <param name="matrix"> /// The matrix to convert. /// </param> /// <returns> /// A string representation of the given matrix. /// </returns> public string ToString(DoubleMatrix1D matrix) { DoubleMatrix2D easy = matrix.Like2D(1, matrix.Size); easy.ViewRow(0).Assign(matrix); return(ToString(easy)); }
/// <summary> /// Outer product of two vectors; Returns a matrix with <i>A[i,j] = x[i] * y[j]</i>. /// </summary> /// <param name="x">the first source vector.</param> /// <param name="y">the second source vector.</param> /// <returns>the outer product </i>A</i>.</returns> private static DoubleMatrix2D XMultOuter(DoubleMatrix1D x, DoubleMatrix1D y) { DoubleMatrix2D A = x.Like2D(x.Size, y.Size); MultOuter(x, y, A); return(A); }