public static VectorR Transform(VectorR v, MatrixR m) { VectorR result = new VectorR(v.GetSize()); if (!m.IsSquared()) { throw new ArgumentOutOfRangeException( "Dimension", m.GetRows(), "The matrix must be squared!"); } if (m.GetRows() != v.GetSize()) { throw new ArgumentOutOfRangeException( "Size", v.GetSize(), "The size of the vector must be equal" + "to the number of rows of the matrix!"); } for (int i = 0; i < m.GetRows(); i++) { result[i] = 0.0; for (int j = 0; j < m.GetCols(); j++) { result[i] += v[j] * m[j, i]; } } return(result); }
public MatrixR ReplaceCol(VectorR v, int n) { if (n < 0 || n > Cols) { throw new ArgumentOutOfRangeException( "n", n, "n is out of range!"); } if (v.GetSize() != Rows) { throw new ArgumentOutOfRangeException( "Vector size", v.GetSize(), "vector size is out of range!"); } for (int i = 0; i < Rows; i++) { matrix[i, n] = v[i]; } return(new MatrixR(matrix)); }
public static VectorR GaussJordan(MatrixR A, VectorR b) { Triangulate(A, b); int n = b.GetSize(); VectorR x = new VectorR(n); for (int i = n - 1; i >= 0; i--) { double d = A[i, i]; if (Math.Abs(d) < 1.0e-500) { throw new ArgumentException("Diagonal element is too small!"); } x[i] = (b[i] - VectorR.DotProduct(A.GetRowVector(i), x)) / d; } return(x); }
public static MatrixR Transform(VectorR v1, VectorR v2) { if (v1.GetSize() != v2.GetSize()) { throw new ArgumentOutOfRangeException( "v1", v1.GetSize(), "The vectors must have the same size!"); } MatrixR result = new MatrixR(v1.GetSize(), v1.GetSize()); for (int i = 0; i < v1.GetSize(); i++) { for (int j = 0; j < v1.GetSize(); j++) { result[j, i] = v1[i] * v2[j]; } } return(result); }
private static double Pivot(MatrixR A, VectorR b, int q) { int n = b.GetSize(); int i = q; double d = 0.0; for (int j = q; j < n; j++) { double dd = Math.Abs(A[j, q]); if (dd > d) { d = dd; i = j; } } if (i > q) { A.GetRowSwap(q, i); b.GetSwap(q, i); } return(A[q, q]); }