/**
* @version 1.2, 04/03/2002 Quitar errores
*/
#ifndef R_SOLV_H
#define R_SOLV_H
//----------------------------------------------------------------------------
#include "../matrixdouble/squaredmatrix.h"
#include "../matrixdouble/vectordouble.h"
#include <iostream>
using namespace std;


// (posada)

// Solves the set of n linear equations R x = b, whereR is an upper triangular matrix stored in
// a and d. a[1..n][1..n] and d[1..n] are input as the output of the routine qrdcmp and
// are not modified. b[1..n] is input as the right-hand side vector, and is overwritten with the
// solution vector on output.
// antes void rsolv(double **a, int n, double d[], double b[])
void rsolv(SquaredMatrix &a, int n, VectorDouble &d, VectorDouble &b)
{
	// cout << "\n{ rsolv";
	// { posada
        // Logica
	a.setLogic(1);
	b.setLogic(1);
	d.setLogic(1);
	// No teclear, compatibilidad de versiones int n = a.getSize();
        // } posada

   int i,j;
   double sum;
   b[n] /= d[n];
   for (i=n-1;i>=1;i--) {
      for (sum=0.0,j=i+1;j<=n;j++)
         sum += a[i][j]*b[j];
      b[i]=(b[i]-sum)/d[i];
   }
	// cout << "\n  } rsolv";
}
/* (C) Copr. 1986-92 Numerical Recipes Software ;#. */
//----------------------------------------------------------------------------
#endif
// Fin------------------------------------------------------------------------