0% found this document useful (0 votes)
15 views3 pages

Debjit Dey - Numerical Lab Assignment 1

Uploaded by

Debjit Dey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Debjit Dey - Numerical Lab Assignment 1

Uploaded by

Debjit Dey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Debjit Dey

Batch: BCS2B
Student ID: 201001001122
Subject: NUMERICAL METHOD LAB
Group: B
ASSIGNMENT 1

PROGRAM: FORWARD INTERPOLATION


SOURCE CODE:
#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 : ");
scanf("%d", &n);
printf("\nEnter the values in form x and 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 : ");
scanf("%f", &x);
h = ax[1] - ax[0];
for (i = 0; i <= n - 1; i++)
diff[i][1] = ay[i + 1] - ay[i];
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];
i = 0;
while (!(ax[i] > x))
i++;
i--;
p = (x - ax[i]) / h;
yp = ay[i];
for (k = 1; k <= ORDER; k++)
{
nr *= p - k + 1;
dr *= k;
yp += (nr / dr) * diff[i][k];
}
printf("\nWhen x = %f, corresponding y = %f\n\n", x, yp);
}

OUTPUT:

You might also like