
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - interpolate.krogh_interpolate() Function
scipy.interpolate.krogh_interpolate() is a function that performs polynomial interpolation based on the Krogh or Hermite method. It computes a polynomial that passes exactly through a given set of points and can also interpolate given derivative values at those points. This function is particularly useful when both function values and derivative information for Hermite interpolation are available.
Syntax
Following is the syntax of the function scipy.interpolate.krogh_interpolate() to perform polynomial interpolation −
scipy.interpolate.krogh_interpolate(xi, yi, x, der=0, axis=0)
Parameters
Here are the parameters of the scipy.interpolate.krogh_interpolate() function −
- xi(array-like): 1-D array of known x-values (data points) where interpolation is performed.
- yi(array-like): Array of y-values corresponding to the known x-values. If Hermite interpolation is required then yi can be a 2D array where each row corresponds to the values and their derivatives at the same point.
- x(array-like): Points at which to evaluate the interpolating polynomial i.e., the new x-values where the polynomial is evaluated.
- axis(int, optional): Axis along which to interpolate if yi is multidimensional.
- der(int or list of int, optional): Specifies the order of the derivative to compute. If der=0 then the function returns the interpolated values. If higher-order derivatives are requested then the function returns the corresponding derivatives at the specified points.
Return Value
The scipy.interpolate.krogh_interpolate() function returns the interpolated y-values or the derivatives if der > 0 at the points specified by x.
Basic Polynomial Interpolation
Following is the example of using the scipy.interpolate.krogh_interpolate() function which is used to perform polynomial interpolation −
from scipy.interpolate import krogh_interpolate import numpy as np import matplotlib.pyplot as plt # Known data points xi = np.array([0, 1, 2]) yi = np.array([1, 3, 2]) # Points where we want to evaluate the interpolating polynomial x_new = np.linspace(0, 2, 100) # Perform interpolation y_new = krogh_interpolate(xi, yi, x_new) # Plot the original points and interpolated values plt.plot(xi, yi, 'o', label='Data Points') # Known points plt.plot(x_new, y_new, label='Krogh Interpolation') # Interpolated curve plt.legend() plt.xlabel('x') plt.ylabel('y') plt.title('Krogh Polynomial Interpolation') plt.grid() plt.show()
Here is the output of the scipy.interpolate.krogh_interpolate() function −

Hermite Interpolation with Derivatives
Hermite interpolation is a type of polynomial interpolation where not only the function values at certain points are provided but also the values of the function's derivatives at those points. Heres an example of how to use KroghInterpolator() function to perform Hermite interpolation when we have derivative information for the points −
import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import KroghInterpolator # Define points (xi) and values/derivatives (yi) xi = np.array([0, 1, 2]) # x-values of points # Values and derivatives at each point: [[y0, y0'], [y1, y1'], [y2, y2']] yi = np.array([[0, 1], # At x=0, y(0)=0, y'(0)=1 [1, 0], # At x=1, y(1)=1, y'(1)=0 [0, -1]]) # At x=2, y(2)=0, y'(2)=-1 # Create the KroghInterpolator object interpolator = KroghInterpolator(xi, yi) # Generate new points for interpolation x_new = np.linspace(0, 2, 100) # Interpolate values at the new points y_new = interpolator(x_new) # Plot original points and the Hermite interpolated polynomial plt.plot(xi, yi[:, 0], 'o', label='Data Points') # Plot data points plt.plot(x_new, y_new, label='Hermite Interpolated Polynomial') # Interpolated curve plt.legend() plt.xlabel('x') plt.ylabel('y') plt.title('Hermite Interpolation with KroghInterpolator') plt.grid() plt.show()
Here is the output of the scipy.interpolate.krogh_interpolate() function which is used for Hermite Interpolation −

Computing First and Second Derivatives
Here is the example which shows how to compute the first and second derivatives with the help of scipy.interpolate.krogh_interpolate() function −
import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import KroghInterpolator # Define points (xi) and values/derivatives (yi) xi = np.array([0, 1, 2]) # x-values of points # Values and derivatives at each point: [[y0, y0'], [y1, y1'], [y2, y2']] yi = np.array([[0, 1], # At x=0, y(0)=0, y'(0)=1 [1, 0], # At x=1, y(1)=1, y'(1)=0 [0, -1]]) # At x=2, y(2)=0, y'(2)=-1 # Create the KroghInterpolator object interpolator = KroghInterpolator(xi, yi) # Generate new points for interpolation x_new = np.linspace(0, 2, 100) # Interpolate values at the new points y_new = interpolator(x_new) # Compute first derivative at new points y_prime = interpolator.derivative(x_new, der=1) # Compute second derivative at new points y_double_prime = interpolator.derivative(x_new, der=2) # Plot original function and its first and second derivatives plt.figure(figsize=(10, 6)) # Plot the interpolated polynomial plt.subplot(3, 1, 1) plt.plot(x_new, y_new, label="Interpolated Polynomial") plt.plot(xi, yi[:, 0], 'o', label="Data Points") plt.title('Hermite Interpolation with KroghInterpolator') plt.ylabel('y') plt.legend() plt.grid() # Plot the first derivative plt.subplot(3, 1, 2) plt.plot(x_new, y_prime, label="First Derivative", color='orange') plt.title('First Derivative') plt.ylabel("dy/dx") plt.legend() plt.grid() # Plot the second derivative plt.subplot(3, 1, 3) plt.plot(x_new, y_double_prime, label="Second Derivative", color='green') plt.title('Second Derivative') plt.xlabel('x') plt.ylabel(r"$d^2y/dx^2$") plt.legend() plt.grid() plt.tight_layout() plt.show()
Here is the output of the scipy.interpolate.krogh_interpolate() function which is used to compute first and second order derivatives −
