Skip to content

Instantly share code, notes, and snippets.

@Cirediallo
Created November 15, 2017 20:11
Show Gist options
  • Save Cirediallo/222e30d016413daf20345761a1a2ced2 to your computer and use it in GitHub Desktop.
Save Cirediallo/222e30d016413daf20345761a1a2ced2 to your computer and use it in GitHub Desktop.
This method uses the newton method to compute the interpolation function on a point x. It takes as parameter a vector representing the abscissae Xi and the ordinates Yi with (Xi, Yi) the interpolation points, the size of the array and the calculation value of the polynomial. It calculates and returns the value of the interpolation polynomial co…
double newton(double *x, double *y, int n,double valeur){
double **difDiv = malloc2(n,n);
int i,j;
//affectation et calcul des differences divisées
for(i = 0; i < n; i++){
difDiv[i][0] = y[i];
printf("Dif[%d][0] ====> %f\n",i,difDiv[i][0]);
}// A LA FIN DE CETTE BOUCLE D[3][0] VAUT 6
for(j = 1; j < n;j++){
for(i = 0; i < n-j; i++){
difDiv[i][j] = (difDiv[i+1][j-1]-difDiv[i][j-1])/(x[i+j]-x[i]);
}
}
double a = 0.0 ;
for(int i = 0 ; i < n ; i++){ // les Dif[0][i]
double terme = difDiv[0][i] ;
for(int j = 0 ; j < i ; j++){ // calcul des facteurs (x-x[j])
terme *= valeur - x[j] ;
}
printf("terme %d = %lf\n", i, terme) ;
a += terme ;
}
free(difDiv);
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment