You are on page 1of 4

Newton Forward Interpolation

Aim: To implement Newton forward interpolation.

Algorithm
Step 1: Start the program
Step 2: Declare x[20], y[20], f, s, d, h, p as float data type and i, j, n as integer data type
Step 3: Read the record n and read the elements of x & y using for loop
Step 4: Calculate h = x[2] – x[1]
Step 5: Read the point which is going to be searched
Step 6: Calculate s = (f –x[1]/h)
p=1
d =y[1]
Step 7: Using for loop calculate p and d
a) y[j] = y[j+1] – y[j-1]
b) p = p * (s* i + 1)/i
c) d = d + p * y[1]
Step 8: print f and d
Step 9: Stop the program
Flowchart

Start

float x[20], y[20], f, s, d, h, p


int i, j ,k, n

read n

False
for(i = 1; i <= n; i++)

read x[i]

for(i = 1; i <= n; i++)

read y[i]

h = x[2] – x[1]

read f

s = f(x[n])/h
p=1
d = y[1]

False
for(i = 1; i <= (n - 1); i++)

False
for(j = 1; j <=(n – 1); j++)

y[j] =y[j + 1] –y[j]

p = p * (s – i + 1)/i
d = d + p * y[1]

print f, d

Stop
Program
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
main()
{
float x[20],y[20],f,s,h,d,p;
int j,i,n;
clrscr();
printf ("**__(57 *’s)__**\n");
printf ("*\t\t\t\t\t\t\t*\n");
printf ("*\t\tForward Interpoaltion\t\t\t*\n");
printf ("*\t\t\t\t\t\t\t*\n**__(57 *’s)__**\n\n");
printf("\nHow many record you will be enter:");
scanf("%d",&n);
printf("enter the elements of x:");
for(i=1;i<=n;i++)
{
scanf("%f",&x[i]);
}
printf("enter the elements of y:");
for(i=1;i<=n;i++)
{
scanf("%f",&y[i]);
}
h=x[2]-x[1];
printf("Enter the value of f:");
scanf("%f",&f);
s=(f-x[1])/h;
p=1;
d=y[1];
for(i=1;i<=(n-1);i++)
{
for(j=1;j<=(n-i);j++)
{
y[j]=y[j+1]-y[j];
}
p=p*(s-i+1)/i;
d=d+p*y[1];
}
printf("\n*//(25 *’s)THE RESULT*//(24 *’s)\n");
printf("For the value of x=%6.5f THe value is %6.5f",f,d);
getch();
return(0);
}
Output

You might also like