/*no se usa en el código pero una implementación a futuro podría ser implementar este tipo de interpolación #include #include #include //#include "algebralineal.h" //#include "interpolacion.h" //#include "gnuplot_i_calnum.h" using namespace std; using namespace CALNUM; inline double fun(double x, int ft) { switch(ft) { case 0: return 1./(1.+25*x*x); break; case 1: return abs(x); break; case 2: return sin(x); case 3: return 2*atan(x) +exp(5-x) + 5*cos(x); } } template int splines(Vector &x, Vector &a, Vector &b, Vector &c, Vector &d) { cout<<"splines naturales"< h(nint); for( int i=0; i u(nint), v(nint); //u(0), v(0) no estan definidos for( int i=1; i0; k--) { c[k]=(v[k]-h[k]*c[k+1])/u[k]; d[k]=(c[k+1]-c[k])/(3*h[k]); } //Valores especiales en x0 c[0]= T(0); d[0]=c[1]/(3*h[0]); b[0]=(a[1]-a[0])/h[0]-c[1]*h[0]/3; // Calculo de b[k] for( int k=0; k int splines_sujetos(Vector &x, Vector &a, Vector &b, Vector &c, Vector &d, T& fp0, T& fp1) { cout<<"splines sujetos"< h(nint); for( int i=0; i u(n), v(n); // Valores especiales de u(0), v(0) u[0]=2*h[0]; v[0]= 3*( (a[1]-a[0])/h[0] -fp0); for( int i=1; i=0; k--) { c[k]=(v[k]-h[k]*c[k+1])/u[k]; d[k]=(c[k+1]-c[k])/(3*h[k]); } //Calculo de b[k] //Valores especiales en x0 b[0]=fp0; for( int k=0; k T eval_splines(T xx, const Vector &x, const Vector &a, const Vector &b, const Vector &c, const Vector &d) { //buscar indice k int n=x.size(); int k=0; int kinf=0; int ksup=n-1; while(ksup-kinf>1) { k=(ksup+kinf)/2; if (x[k]>xx) ksup=k; else kinf=k; } k=kinf; // cout<<"xx= "<>nd; //Construccion de vectores de nodos Vector x(nd); cout<<"Entrar valores de los nodos"<>x[i]; double x0=x[0], x1=x[nd-1]; //Eleccion de la funcion a interpolar int ft=-1; while((ft!=0)&&(ft!=1)&&(ft!=2)&&(ft!=3)) { cout<<"Entrar funcion: 0- Runge 1- Bernstein 2- sin(x)" <<" 3- user "<>ft; } //Calculo de las ordenadas de interpolacion y de los coeficientes del //polinomio Vector < double > y(nd); for (int i=0; i< nd; i++) y[i]=fun(x[i],ft); //Derivadas en los extremos double fp0,fp1; //Calculo de las derivadas en los extremos //Se puede fijar el error de la derivada por extrapolacion double hhh=0.00001; fp0= (fun(x0+hhh,ft)-fun(x0-hhh,ft))/(2*hhh); fp1=(fun(x1+hhh,ft)-fun(x1-hhh,ft))/(2*hhh); int nint= nd - 1; Vector b(nint), c(nd), d(nint); //Impresion de los nodos cout<<" x y"< a=y; splines(x,y,b,c,d); //evaluacion del polinomio y funcion en los puntos de dibujo (200) int n=200; double hh=(x1-x0)/n; n++; Vector xx(n), yy(n) ,ff(n); cout<<" x " << " f(x) "<< " splin(x)" <(xx[i], x, y, b,c,d); ff[i] = fun(xx[i],ft); if(!(i-(i/5)*5)) cout<(x,y,b,c,d, fp0,fp1); cout<(xx[i], x, y, b,c,d); ff[i] = fun(xx[i],ft); if(!(i-(i/5)*5)) cout<