Ejemplo n.º 1
0
SquareMatrix SqMRO_LUBackSubstitution::operator()(RowVector &indx, RowVector &b) const {

	SquareMatrix a(*m_thisMatrix);
	int n, i, j, ip, ii = -1;
	double sum;

	n = a.getRows();

	for (i = 0; i < n; i++) {
		ip = (int)indx(i);
		sum = b.element(ip);
		b.element(ip) = b.element(i);
		if (ii != -1) {
			for (j = ii; j < i; j++) {
				sum -= a.element(i,j) * b.element(j);
			}
		} else if (sum) {
			ii = i;
		}
		b.element(i) = sum;
	}
	for (i = (n - 1); i >= 0; i--) {
		sum = b.element(i);
		for (j = (i + 1); j < n; j++) {
			sum -= a.element(i,j) * b.element(j);
		}
		b.element(i) = sum / a.element(i,i);
	}

	return a;
}
Ejemplo n.º 2
0
void SpinAdapted::Wavefunction::CollectFrom (const RowVector& C)
{
  int flatIndex = 0;
  for (int lQ = 0; lQ < nrows (); ++lQ)
    for (int rQ = 0; rQ < ncols (); ++rQ)
      if (allowedQuantaMatrix (lQ, rQ))
        for (int lQState = 0; lQState < operator_element(lQ, rQ).Nrows (); ++lQState)
          for (int rQState = 0; rQState < operator_element(lQ, rQ).Ncols (); ++rQState)
	    {
	      operator_element(lQ, rQ).element (lQState, rQState) = C.element (flatIndex);
	      ++flatIndex;
	    }
}
Ejemplo n.º 3
0
SquareMatrix SqMRO_LUDecomposition::operator()(RowVector &indx, double *d) const {

	SquareMatrix a(*m_thisMatrix);
	int n, i, imax, j, k;
	double big, dum, sum, temp;
	RowVector vv(a.getRows());

	n = a.getRows();

	// No row interchanges yet
	*d = 1.0;

	// Loop over rows to get implicit scaling information
	for (i = 0; i < n; i++) {
		big = 0.0;
		for (j = 0; j < n; j++) {
			temp = fabs(a.element(i,j));
			if (temp > big) {
				big = temp;
			}
		}
		if (big == 0.0) {
			error("SquareMatrixAlias::luDecomp : MatrixAlias is rank defficient\n\n");
			return a;
		}
		vv(i) = 1 / big;
	}

	// Loop over columns (Crout's method)
	for (j = 0; j < n; j++) {
		for (i = 0; i < j; i++) {
			sum = a.element(i,j);
			for (k = 0; k < i; k++) {
				sum -= a.element(i,k) * a.element(k,j);
			}
			a.element(i,j) = sum;
		}
		big = 0;
		for (i = j; i < n; i++) {
			sum = a.element(i,j);
			for (k = 0; k < j; k++) {
				sum -= a.element(i,k) * a.element(k,j);
			}
			a.element(i,j) = sum;

			dum = vv(i) * fabs(sum);
			if (dum >= big) {
				big = dum;
				imax = i;
			}
		}
		if (j != imax) {
			for (k = 0; k < n; k++) {
				dum = a.element(imax,k);
				a.element(imax,k) = a.element(j,k);
				a.element(j,k) = dum;
			}
			*d = -(*d);
			vv(imax) = vv(j);
		}
		indx.element(j) = imax;
		// Singularity may arise as aresult of rounding errors
		// Substitute in small values for zeros
		if (a.element(j,j) == 0) {
			error("SquareMatrixAlias::luDecomp : MatrixAlias is rank defficient\n\n");
			a.element(j,j) = 1e-100;
		}
		if (j != n) {
			dum = 1 / a.element(j,j);
			for (i = j+1; i < n; i++) {
				a.element(i,j) *= dum;
			}
		}
	}

	return a;
}