// Compilar con g++ - I. - I./templates dif_div.cpp
#include <cmath>
#include <iostream>
#include "algebralineal.h"
#include "interpolacion.h"
using namespace std;
using namespace CALNUM;

int
main()
{

    //Orden polinomio interpolador
    int nd = 4;

    //Valores(x, y)
    double tempx[] = {3, 1, 5, 6};
    double tempy[] = {1., -3., 2., 4.};

    Vector < double >x(nd);

    //Construccion de vectores
	for (int i = 0; i < nd; i++)
	x[i] = tempx[i];
    Vector < double >y(nd);

    for (int i = 0; i < nd; i++)
	y[i] = tempy[i];
    Vector < double >a = difdiv < double >(x, y);

    cout << "coeficientes diferencias divididas a= " << a << endl;
    //Comprobacion valores en puntos de interpolacion
	cout << " x " << "y " << endl;
    int n = x.size();

    for (int i = 0; i < n; i++) {
	double xx = x[i];
	double yy = eval_difdiv < double >(xx, x, a);

	cout << xx << "  " << yy << endl;
    }
    //Valor en x = 0
	double xx = 0.;
    double yy = eval_difdiv(xx, x, a);

    //
	cout << 0 << "  " << yy << endl;

    return 0;
}
