Cara menggunakan derivative interpolation python

In this article, we will learn Interpolation using the SciPy module in Python. First, we will discuss interpolation and its types with implementation.

Interpolation and Its Types

Interpolation is a technique of constructing data points between given data points. The scipy.interpolate is a module in Python SciPy consisting of classes, spline functions, and univariate and multivariate interpolation classes. Interpolation is done in many ways some of them are :

  • 1-D Interpolation
  • Spline Interpolation
  • Univariate Spline Interpolation
  • RBF Interpolation

Let’s discuss all the methods one by one and visualize the results.

1-D Interpolation

To create a function based on fixed data points, scipy.interpolate.interp1d is used. It takes data points x and y and returns a function that can be called with new x and returns the corresponding y point.

Syntax: scipy.interpolate.interp1d(x , y , kind , axis , copy , bounds_error , fill_value , assume_sorted)

Python




# Import the required Python libraries

import matplotlib.pyplot as plt

from scipyimport interpolate

import numpy as np

  

import0

import1import2 import3import4import5import6import7

import8import2 import1matplotlib.pyplot as plt1matplotlib.pyplot as plt1matplotlib.pyplot as plt3

  

matplotlib.pyplot as plt5

matplotlib.pyplot as plt6import2 matplotlib.pyplot as plt8

matplotlib.pyplot as plt9import2 import3import4import5from4import5from6import7

from8import2 scipy0

  

scipy2scipy3import7

scipy5scipy6scipy7scipy8scipy9import2import1import7

import3

Output:

Cara menggunakan derivative interpolation python

 

Spline Interpolation

In spline interpolation, a spline representation of the curve is computed, and then the spline is computed at the desired points. The function splrep is used to find the spline representation of a curve in a two-dimensional plane.

  • To find the B-spline representation of a 1-D curve, scipy.interpolate.splrep is used.

Syntax: scipy.interpolate.splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet)

  • To compute a B-spline or its derivatives, scipy.interpolate.splev is used.

Syntax: scipy.interpolate.splev(x , tck , der , ext)

Python




# Import the required Python libraries

import numpy as np

import matplotlib.pyplot as plt

from scipyimport interpolate

  

interpolate4

import1import2 import3import4import5import6import7

import8import2 import4matplotlib.pyplot as plt1matplotlib.pyplot as plt1import7import7

  

matplotlib.pyplot as plt5

numpy as np1

numpy as np2

numpy as np3

matplotlib.pyplot as plt6import2 numpy as np6import2import4import7

matplotlib.pyplot as plt9import2 import3import4 4matplotlib.pyplot as plt1matplotlib.pyplot as plt1matplotlib.pyplot as plt3 4 9import00import7

from8import2 import04import2import4import7

  

import09

  

scipy5scipy6import13

import14import15import16scipy9import2import1import7

  

import22import23import5import25import5import27import28

import29import30import31import5import33import5import30import36import5import36import28

scipy2import41import7

import3

Output:

Cara menggunakan derivative interpolation python

Univariate Spline

It is a 1-D smoothing spline that fits a given group of data points. The scipy.interpolate.UnivariateSpline is used to fit a spline y = spl(x) of degree k to the provided x, y data. s specifies the number of knots by specifying a smoothing condition. The scipy.interpolate.UnivariateSpline. set_smoothing_factor: Spline computation with the given smoothing factor s and with the knots found at the last call.

Syntax: scipy.interpolate.UnivariateSpline( x, y, w, bbox, k, s, ext)

Python




import44

import matplotlib.pyplot as plt

from import48import import50

  

import1import2 import54import30import7import5import7import5import60import7

import8import2 import64import30import1matplotlib.pyplot as plt1matplotlib.pyplot as plt1matplotlib.pyplot as plt3import7import71 import31 matplotlib.pyplot as plt1 import74import60import7

scipy2import78import7

scipy5import81import82import2import84import7

  

import87

import88

import89import2 import91

import92import2 import54import30import7import5import7import5matplotlib.pyplot as plt00import7

matplotlib.pyplot as plt02matplotlib.pyplot as plt03matplotlib.pyplot as plt04import2import7import7

  

matplotlib.pyplot as plt09

matplotlib.pyplot as plt10matplotlib.pyplot as plt11import7

matplotlib.pyplot as plt13import2matplotlib.pyplot as plt15matplotlib.pyplot as plt04import2import7import7

import3

Output:

Cara menggunakan derivative interpolation python

Radial basis function for Interpolation

The scipy.interpolate.Rbf is used for interpolating scattered data in n-dimensions. The radial basis function is defined as corresponding to a fixed reference data point. The scipy.interpolate.Rbf is a class for radial basis function interpolation of functions from N-D scattered data to an M-D domain.