C Program For Newton’s Backward Interpolation

Newton’s backward interpolation is another way of approximating a function with an nth degree polynomial passing through (n+1) equally spaced points.

Newton’s Backward Interpolation Formula

Newton's Backward Interpolation Formula

Newton’s Backward Interpolation Example

Find Solution using Newton’s Backward Difference formula

xf(x)
189146
190166
191181
192193
1931101

x = 1925

Solution:
The value of the table for x and y

x18911901191119211931
y46668193101

Newton’s backward difference table is

xyy∇2y∇3y∇4y
189146
20
190166-5
152
191181-3-3
12-1
192193-4
8
1931101
Newton’s Backward Interpolation Example Solution

C Program

//Newton's Backward Difference
//This code is written by Souvik Ghosh
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float u_cal(float u, int n)
{
	float temp = u;
	for (int i = 1; i < n; i++)
		temp = temp * (u + i);
	return temp;
}
int fact(int n)
{
	int f = 1;
	for (int i = 2; i <= n; i++)
		f *= i;
	return f;
}

void main()
{
	int n=0;
	printf("Please Enter the number of values: ");
	scanf("%d",&n);
	float x[n],y[n][n];
	printf("Please enter the values of x:\n");
	for(int i=0;i<n;i++){
        scanf("%f",&x[i]);
	}
	printf("Please enter the values of y:\n");
	for(int i=0;i<n;i++){
        scanf("%f",&y[i][0]);
	}


	for (int i = 1; i < n; i++) {
		for (int j = n - 1; j >= i; j--)
			y[j][i] = y[j][i - 1] - y[j - 1][i - 1];
	}


	printf("Displaying the backward difference table.....\n\n");
	for (int i = 0; i < n; i++) {
            printf("%0.2f\t\t",x[i]);
		for (int j = 0; j <= i; j++)
			printf("%0.2f\t\t",y[i][j]);

		printf("\n");
	}


	float value = 0;
	printf("Please enter the value of f\n");
	scanf("%f",&value);

	float sum = y[n - 1][0];
	float u = (value - x[n - 1]) / (x[1] - x[0]);
	for (int i = 1; i < n; i++) {
		sum = sum + (u_cal(u, i) * y[n - 1][i]) /
									fact(i);
	}

	printf("Value at %0.4f is %0.4f\n",value,sum);

}

Output Terminal

Newton's Backward Interpolation Output

Related Posts

Artificial Intelligence Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Artificial Intelligence Suggestions! Elevate Your Learning Experience and Excel with Confidence.

Mixed Signal Design Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Mixed Signal Design Suggestions! Elevate Your Learning Experience and Excel with Confidence.

Fiber Optic Communication Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Fiber Optic Communication Suggestions! Elevate Your Learning Experience and Excel with Confidence.

Cyber Security Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Cyber Security Suggestions! Elevate Your Learning Experience and Excel with Confidence.

MAKAUT 7th Semester Examination Questions – 2023

Mobile Communication and Networks (PE-EC701C) Neural Network and Fuzzy Logic Control (PE-EC702C/PEROB701B) Principles of Management (HS-HU701)

CSS Cheatsheet

Transform your web design game with my CSS cheatsheet! Master the art of styling, dive into essential properties and selectors, and create visually stunning websites effortlessly. Whether…

Leave a Reply

Your email address will not be published. Required fields are marked *