Вы находитесь на странице: 1из 2

#include<iostream>

#include<cmath>
int i, j;
float g,a[100],ya,z[100][100],prod,xo;
using namespace std;
void main()
{
cout<<"\t"<<"INTERPOLACION"<<endl;
cout<<"\n";
cout<<" DIFERENCIAS DIVIDIDAS DE NEWTON"<<endl;
cout<<"\t *"<<"!!!!! Identifique en la tabla quien es x y F(x) !!!!!"
<<endl;
cout<<"\t *"<<"Digite valor a interpolar (x) = ";cin>>xo;
cout<<endl;
cout<<"\t *"<<"Digite grado de polinomio = ";cin>>g;
cout<<endl;
cout<<"\t *"<<"!!! Segun la tabla dada !!! "<<endl;
cout<<"Digite los "<<g+1<<" datos tabulados cercanos a "<<xo<<" E inmed
iatamente su respectivo valor de F(x) ";
cout<<endl;
/////////////////////////////////////////////// Tabla de Datos /////////
////////////////////////////
for (i = 0; i <= g; i++)
{
cout<<endl;
cout << " x("<<i<<") = "; cin >> a[i];
cout << " F(x"<<i<<") = ";cin >> z[i][0];
}
for(int j=1; j<g+1; j++)
{
for(int i=0; i<g+1-j; i++)
{
z[i][j]= (z[i+1][j-1]-z[i][j-1])/(a[i+j]-a[i]);
}
}

ya=z[0][0];
prod=1;
for(int j=0; j<g+1-1; j++)
{
prod=prod*(xo-a[j]);
ya=ya+ z[0][j+1]*prod;
}
cout<<endl;
cout<<"La interpolacion de newton dice que :"<<"\n";
cout<<endl;
cout<<"para x = "<<xo<<" F(X) = "<<ya<<"\n";
cout<<endl;

cout<<"Fin del metodo"<<endl;


cout<<endl;
system("pause");
}

Вам также может понравиться