public WrapperDoubleMatrix1D(DoubleMatrix1D newContent) { if (newContent != null) { Setup(newContent.Count()); } this.Content = newContent; }
public void Solve(DoubleMatrix1D B) { //algebra.property().checkRectangular(LU); int m = M; int n = N; if (B.Count() != m) { throw new ArgumentException("Matrix dimensions must agree."); } if (!this.IsNonsingular) { throw new ArgumentException("Matrix is singular."); } // right hand side with pivoting // Matrix Xmat = B.getMatrix(piv,0,nx-1); if (this.workDouble == null || this.workDouble.Length < m) { this.workDouble = new double[m]; } Algebra.Permute(B, this.piv, this.workDouble); if (m * n == 0) { return; // nothing to do } // Solve L*Y = B(piv,:) for (int k = 0; k < n; k++) { double f = B[k]; if (f != 0) { for (int i = k + 1; i < n; i++) { // B[i] -= B[k]*LU[i][k]; double v = LU[i, k]; if (v != 0) { B[i] = B[i] - f * v; } } } } // Solve U*B = Y; for (int k = n - 1; k >= 0; k--) { // B[k] /= LU[k,k] B[k] = B[k] / LU[k, k]; double f = B[k]; if (f != 0) { for (int i = 0; i < k; i++) { // B[i] -= B[k]*LU[i][k]; double v = LU[i, k]; if (v != 0) { B[i] = B[i] - f * v; } } } } }