# Gauss’s Forward Interpolation

Interpolation refers to the process of creating new data points given within the given set of data. The below code computes the desired data point within the given range of discrete data sets using the formula given by Gauss and this method is known as Gauss’s Forward Method.

Gauss’s Forward Method:

The gaussian interpolation comes under the Central Difference Interpolation Formulae. Suppose we are given the following value of y=f(x) for a set values of x:
X: x0 x1 x2 â€¦â€¦â€¦. xn
Y: y0 y1 y2 â€¦â€¦â€¦â€¦ yn
The differences y1 â€“ y0, y2 â€“ y1, y3 â€“ y2, â€¦â€¦, yn â€“ ynâ€“1 when denoted by Î”y0, Î”y1, Î”y2, â€¦â€¦, Î”ynâ€“1 are respectively, called the first forward differences. Thus the first forward differences are :
Î”y0 = y1 – y0
and in the same way we can calculate higher order differences.

And after the creating table we calculate the value on the basis of following formula:

Now, Let’s take an example and solve it for better understanding.
Problem:
From the following table, find the value of e1.17 using Gauss’s Forward formula.

Solution:
We have
yp = y0 + pÎ”y0 + (p(p-1)/2!).Î”y20 + ((p+1)p(p-1)/3!).Î”y30 + …
where p = (x1.17 – x1.15) / h
and h = x1 – x0 = 0.05
so, p = 0.04
Now, we need to calculate Î”y0, Î”y20, Î”y30 … etc.

Put the required values in the formula-
yx = 1.17 = 3.158 + (2/5)(0.162) + (2/5)(2/5 – 1)/2.(0.008) …
yx = 1.17 = 3.2246
Code: Python code for implementing Gauss’s Forward Formula

## Python3

 `# Python3 code for Gauss's Forward Formula``# importing library``import` `numpy as np` `# function for calculating coefficient of Y ``def` `p_cal(p, n): ` `    ``temp ``=` `p; ``    ``for` `i ``in` `range``(``1``, n): ``         ``if``(i``%``2``=``=``1``):``             ``temp ``*` `(p ``-` `i)``         ``else``:``             ``temp ``*` `(p ``+` `i)``    ``return` `temp; ``# function for factorial``def` `fact(n): ``    ``f ``=` `1``    ``for` `i ``in` `range``(``2``, n ``+` `1``): ``        ``f ``*``=` `i``    ``return` `f ` `# storing available data``n ``=` `7``; ``x ``=` `[ ``1``, ``1.05``, ``1.10``, ``1.15``, ``1.20``, ``1.25``, ``1.30` `]; ` `y ``=` `[[``0` `for` `i ``in` `range``(n)] ``        ``for` `j ``in` `range``(n)]; ``y[``0``][``0``] ``=` `2.7183``; ``y[``1``][``0``] ``=` `2.8577``; ``y[``2``][``0``] ``=` `3.0042``;``y[``3``][``0``] ``=` `3.1582``;  ``y[``4``][``0``] ``=` `3.3201``; ``y[``5``][``0``] ``=` `3.4903``; ``y[``6``][``0``] ``=` `3.6693``; ` `# Generating Gauss's triangle``for` `i ``in` `range``(``1``, n): ``    ``for` `j ``in` `range``(n ``-` `i): ``        ``y[j][i] ``=` `np.``round``((y[j ``+` `1``][i ``-` `1``] ``-` `y[j][i ``-` `1``]),``4``); ` `# Printing the Triangle ``for` `i ``in` `range``(n): ``    ``print``(x[i], end ``=` `"\t"``); ``    ``for` `j ``in` `range``(n ``-` `i): ``        ``print``(y[i][j], end ``=` `"\t"``); ``    ``print``(""); ` `# Value of Y need to predict on ``value ``=` `1.17``; ` `# implementing Formula``sum` `=` `y[``int``(n``/``2``)][``0``]; ``p ``=` `(value ``-` `x[``int``(n``/``2``)]) ``/` `(x[``1``] ``-` `x[``0``])` `for` `i ``in` `range``(``1``,n): ``    ``# print(y[int((n-i)/2)][i])``    ``sum` `=` `sum` `+` `(p_cal(p, i) ``*` `y[``int``((n``-``i)``/``2``)][i]) ``/` `fact(i)` `print``(``"\nValue at"``, value, ``    ``"is"``, ``round``(``sum``, ``4``)); `

Output :

```1       2.7183  0.1394  0.0071  0.0004  0.0     0.0     0.0001
1.05    2.8577  0.1465  0.0075  0.0004  0.0     0.0001
1.1     3.0042  0.154   0.0079  0.0004  0.0001
1.15    3.1582  0.1619  0.0083  0.0005
1.2     3.3201  0.1702  0.0088
1.25    3.4903  0.179
1.3     3.6693

Value at 1.17 is 3.2246```

Time complexity: O(n2)
Auxiliary space: O(n*n)

Previous
Next