Change language

Gaussian forward interpolation

Interpolation refers to the process of creating new data points specified in a given dataset. The code below calculates the required data point in a given range of discrete datasets using a formula given by Gauss, and this method is known as the Gaussian forward method.

Gaussian forward method:

Gaussian interpolation falls under the Central Difference Interpolation Formulas. Suppose we are given the following value y = f (x) for given values ​​of x:
X: x0 x1 x2 ………. xn
Y: y0 y1 y2 ………… yn
Differences y1 — y0, y2 — y1, y3 — y2, ……, yn — yn - 1, denoted as Δy0, Δy1, Δy2, ……, Δyn - 1, respectively, are called the first forward differences. So the first forward differences are:

Δy 0 = y 1 — y 0

and in the same way we can calculate higher order differences.

And after creating the table, we calculate the value using the following formula:

Now let’s take example and solve it for better understanding. 
Problem:
In the following table, find the value of e 1.17, using the Gauss Forward formula.

x 1.00 1.05 1.10 1.15 1.20 1.25 1.30
ex2.7183 2.8577 3.0042 3.1582 3.3201 3.4903 3.6693

Solution:
We have

y p = y 0 + pΔy 0 + (p (p-1) / 2!). Δy 2 0 + ((p + 1) p (p-1) / 3!). Δy 3 0 + ...

where p = (x 1.17 — x 1,15 ) / h
and h = x 1 — x 0 = 0.05
so p = 0.04

Now we need to calculate Δy 0 , Δy 2 0 , Δy 3 0 ... etc.

Put the required values ​​into the formula
y x = 1 , 17 = 3.158 + (2/5) (0.162) + (2/5) (2/5 — 1) / 2. (0.008) ...
y x = 1.17 = 3.2246

Code: Python code to implement Gauss Formula

# Python3 code for straight Gauss formula
# library import

import numpy as np

 
# function to calculate the Y coefficient

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

 
# storage available small 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

 
# Generate a Gaussian 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 ); 

 
# Print triangle

for i in range (n): 

print (x [i], end = "" ); 

for j in range (n - i): 

print (y [i] [j], end = "" ); 

print (""); 

 
# Y value should be predicted to

value = 1.17

 
# embedding the 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 ((ni) / 2)] [i])

  sum = sum + (p_cal (p, i) * y [ int ((n - i) / 2 )] [i]) / fact (i)

 

print ( "Value 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 at 1.17 is 3.2246 

Shop

Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best laptop for development

$499+
Gifts for programmers

Best laptop for Cricut Maker

$299+
Gifts for programmers

Best laptop for hacking

$890
Gifts for programmers

Best laptop for Machine Learning

$699+
Gifts for programmers

Raspberry Pi robot kit

$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically