Write a program to demonstrate Newton-Forward Interpolation formula in C language.

Tested on: Turbo C++ Version 4.0Time Complexity: O (n2)Space Complexity: O (n2)Open Source: MIT
1
2
3
        /*Program to execute Newton Forward Interpolation */
4
	#include <stdio.h>
5
	#include <conio.h>
6
	#define max 50
7
	void main()
8
	{
9
	    float arrx[max + 1], arry[max + 1], diff[max + 1][5], num = 1.0, den = 1.0;
10
	    float x, p, h, y;
11
	    int i, j, k, n;
12
	    print("Enter the value of n: ");
13
	    scanf("%d", &n);
14
	    printf("Enter values for x and y:\n"); /*Input data */
15
	    for (i = 0; i <= n - 1; i++)           /* Calculate First difference*/
16
	        scanf("%f %f", &arrx[i], &arry[i]);
17
	    printf("\nEnter value of x for which value of y is needed: ");
18
	    scanf("%f", &x);
19
	    h = arrx[1] - arrx[0];
20
	    for (i = 0; i < n - 1; i++) /* calculate frist difference */
21
	        diff[i][1] = arry[i + 1] - arry[i];
22
	    for (j - 2; j < 5; j++) /* calculate other difference  */
23
	        for (i - 0; i <= n - j; i++)
24
	            diff[i][j] = diff[i + 1][i + 1] - diff[i][j - 1];
25
	    i = 0;
26
	    while (arry[i + 1] < x) /*search for x0,y0 */
27
	        i++;
28
	    p = (x - arry[i + 1]) / h;
29
	    y = arry[i];
30
	    for (k = 1; k < 5; k++) /* apply interpolation formula */
31
	    {
32
	        num *= p - k + 1;
33
	        den *= k;
34
	        y += (num / den) * diff[i][k];
35
	    }
36
	    printf("value of y = %f ,  when  x = %f", y, x);
37
	    getch();
38
	}",
39
           
40
        

Output

1
2
3
        Enter the value of n: 6
4
	Enter values of x and y:
5
	100 10.63
6
	150 13.03
7
	200 15.04
8
	250 16.81
9
	300 18.42
10
	350 19.90
11
	400 21.27
12
	
13
	Enter value of x for which value of y is needed: 218
14
	Value of y = 15.754879, when x = 218.000000"

Rate the Code

Reviews are published after a quick safety check (usually within 24 hours).

Reviews are public. Developers can see basic device specifications to respond. Learn more

How to run Newton Forward Interpolation Method program in C-Language?

To run Newton Forward Interpolation Method program in C-Language, follow the below mentioned steps:

  1. Copy the Code: Press the copy button in the code block to copy the complete code.
  2. Open Turbo C++ Version 4: Open the Turbo C++ (Version 4) software on your system.
  3. Paste the code: Paste the copied code into Turbo C++’s editor.
  4. Compile the Code: Compile the program by pressing the Alt+F9 keys. This shows you the errors and warnings, if any.
  5. Run the code: Press the Ctrl+F9 keys to run the program if the program is successfully compiled.
  6. Enter the Input: Provide the required inputs or your desired inputs, if applicable.
  7. Receive the Result: Get the result of the program on the screen based on the provided inputs.

More about the Newton-Forward Interpolation Formula

Discovered by: Sir Isaac Newton

Discovery Year: 1667

Aim: To find the estimate of missing data points from serial data like yearly based data or quarterly and the gap between the intervals is the same then the Newton-interpolation formula comes into the picture.

How does the Newton-Forward Interpolation Formula work?

  1. Make a forward difference table in the table the difference between the successive values calculated.
  2. Use the below-mentioned formula

Image

Where

Image
and x is the base point to calculate the answer.

Why is Newton-Forward Interpolation used?

If there is experimental data or measurement data (data of every hour or every day) and you want to find out the missing values, then this formula is used without making complete equations, and this formula gives an accurate answer.

Real Life Applications of Newton-Forward Interpolation

  1. Scientific Experiments & Lab Data: when there is no direct value available in the data table, then the scientist uses this formula to get the initial readings.
  2. Engineering and Surveying: to find out the precise height or distance at equal intervals for mapping as well as land surveying.
  3. Predict past Missing Data: with the help of this, we can predict the missing data by interpolating the values at the basis of months or years of data to analyze statistical and financial data

Limitations of Newton-Forward Interpolation

  1. Equal gap between intervals: It will work if and only if the gap between the intervals is equal.
  2. Chances of error at the ending part of the table: Works well at the beginning of the table, but if we calculate the values for the table endpoints, then there are higher chances of errors. To solve this error problem, the Newton-Backward Formula is used.
  3. Risk in High-Degree Polynomials: If the data points are very high, then due to the high-order difference, the calculations may be very big that causes the rounded errors.

Alternate Methods

  1. Newton-Backward Interpolation works well if you want to calculate the values at the ending part of the table. Newton-Backward is more efficient than the Newton-Forward interpolation formula.
  2. Lagrange’s Interpolation Formula : If the gap between the intervals is not equal, then the Lagrange interpolation formula is more efficient.
License: This program's source code is open-sourced under the MIT License, while the rest of the program's text content and overall dhimanp platform and brand content remain proprietary under dhimanp.

Submit your modified code

Your submissions are published after a quick safety check (usually within 7 days).

Submissions are public. Developers can see basic device specifications to respond. Learn more

Disclaimer

The information that you shared with us will be publicly visible, and everyone can see your information. And we (dhimanp) are not responsible if anyone misuses this information. We can remove any submitted code at any time for better transparency.

Privacy Policy

If you share your data with us by submitting your code for credit, then we may show your full name, school or college name, and city name on our website.

We are not using this data to track you and are not selling this data to anyone.

If you want to remove your name from our website, you can contact us, and we will remove your name from our website. In the removal process, full credit, including your full name, school or college, city, and code, will be removed from our website.