Posts

Showing posts with the label Newton forward interpolation method

Write a C program on Newton forward interpolation method by MistarAV

#include<stdio.h> #define MAXN 100 #define ORDER 4 int main() { float ax[MAXN+1], ay [MAXN+1], diff[MAXN+1][ORDER+1], nr=1.0, dr=1.0,x,p,h,yp; int n,i,j,k; printf("\nEnter the value of n:\n"); scanf("%d",&n); printf("\nEnter the values in form x,y:\n"); for (i=0;i<=n;i++) scanf("%f %f",&ax[i],&ay[i]); printf("\nEnter the value of x for which the value of y is wanted: \n"); scanf("%f",&x); h=ax[1]-ax[0]; //now making the difference table //calculating the 1st order of differences for (i=0;i<=n-1;i++) diff[i][1] = ay[i+1]-ay[i]; //now calculating the second and higher order differences for (j=2;j<=ORDER;j++) for(i=0;i<=n-j;i++) diff[i][j] = diff[i+1][j-1] - diff[i][j-1]; //now finding x0 i=0; while (!(ax[i]>x)) i++; //now ax[i] is x0 and ay[i] is y0 i--; p = (x-ax[i])/

Write a C program on Newton forward interpolation method by MistarAV

#include<stdio.h> #include<math.h> int fact(int); void main() { float arr[10][11],x,h,p,y,px=1; int i,j,n,ch=30; printf("\nEnter the number of data:"); scanf("%d",&n); printf("\nEnter the data"); for(i=0;i<n;i++) { printf("X%d=",i+1); scanf("%f",&arr[i][0]); printf("Y%d=",i+1); scanf("%f",&arr[i][1]); } //Forming difference table. for(j=2;j<=n;j++) for(i=0;i<n-1;i++) arr[i][j]=arr[i+1][j-1]-arr[i][j-1]; //Printing table printf("\nDifference table is:-"); printf("\n\tx\tY"); for(i=0;i<=n-2;i++) printf("\t%c^%dY",ch,i+1); for(i=0;i<n;i++) {printf("\n"); for(j=0;j<n+1-i;j++) {printf("\t%.4f",arr[i][j]); } } //Take the value of x for f(x) printf("\nEnter the value x for function f(x):"); scanf("%f",&x); //Calculate the value of f(x) for x h=arr[1][0]-arr[0][0]; p=(x-arr[0][0])/h; y=arr[0][1]; for(i=1;i<n