Newton’s Divided Difference Method
Source Code:
Write a program in C to find 𝒚 at 𝒙 = 𝟑 using Newton’s Divided Difference Method given data:
x: 1, 2, 4
y: 1, 4, 16
#include <stdio.h>
#include <conio.h>
int main() {
clrscr();
double x[3] = {1, 2, 4}, y[3] = {1, 4, 16}, p[3][3], xp = 3, yp;
int i, j; // Declare loop variables here (outside loops)
for (i = 0; i < 3; i++)
p[i][0] = y[i];
for (j = 1; j < 3; j++)
for (i = 0; i < 3 - j; i++)
p[
i][j] = (p[i + 1][j - 1] - p[i][j - 1]) / (x[i + j] - x[i]);
yp = p[0][0] + (xp - x[0]) * p[0][1] + (xp - x[0]) * (xp - x[1]) * p[0][2];
printf("\n\n\ty(%.1f) = %.2f\n", xp, yp);
getch();
return 0;
}
Output

