Linear Interpolation
Linear Interpolation is the simplest form of interpolation used to estimate a value between two known data points. It assumes that the change between the points follows a straight line. While :math:Polyfit seeks to find a single curve for an entire dataset, linear interpolation works "locally" between adjacent coordinates.
1. The Mathematical Formula
Given two points and , the value :math:y for any :math:x in the interval is calculated as:
This formula represents the weighted average of the two endpoints based on how close :math:x is to either side.
2. Implementation in SepalSolver
In SepalSolver, the Interp1 method performs 1D linear interpolation. It first searches the input array to find the correct "bin" (the two closest :math:x values) and then applies the linear formula.
Example 1C#
Interpolated value at 5 is 50
Examples
.. Admonition:: Example 1 : Reading Steam Tables
Engineers often use tables of data where values are only provided at fixed intervals (e.g., every 5 degrees). Linear interpolation allows for the estimation of properties at specific, non-tabulated temperatures.
Example 2C#
Estimated pressure at 107.5C: :math:132.05 kPa
.. Admonition:: Example 2 : Lookup Tables in Control Systems
In real-time control, complex mathematical functions are often replaced by "lookup tables" to save processing power. Linear interpolation provides a fast way to get reasonably accurate intermediate values from these tables.
Example 3C#
Torque at 2500 RPM: :math:`295` Nm
Exercise: Manual Implementation
Task: Implement the core logic of a linear interpolator between two specific points.
Example 4C#
2D Linear Interpolation (Interp2)
2D Interpolation, or Bilinear Interpolation, is used to estimate values of a function when the data is provided as a grid. This is essential in fields like meteorology (mapping temperatures across a geographic area) or structural engineering (calculating stress over a surface).
1. How it Works
Bilinear interpolation is essentially a two-step linear interpolation. To find the value at a point inside a rectangular cell defined by four points:
- Interpolate along X: Perform linear interpolation between the points in the -direction to find two intermediate values at the target coordinate.
- Interpolate along Y: Perform a final linear interpolation between those two intermediate values in the -direction to find the result .
2. Data Structure
In SepalSolver, Interp2 requires: double[] X: A vector of coordinates for the columns. double[] Y: A vector of coordinates for the rows. * double[,] Z: A 2D matrix where Z[i, j] is the value at (X[j], Y[i]).
Example 5C#
Value at (0.5, 0.5): 25
Examples
.. Admonition:: Example 1 : Topographic Height Estimation
Imagine you have a grid of elevation data from a survey. You want to know the height at a specific coordinate that wasn't directly measured.
Example 6C#
Height at (100.5, 50.5): :math:537.5 m
.. Admonition:: Example 2 : Pressure Mapping
In aerodynamics, sensors on a wing provide pressure data at specific points. Interp2 allows the solver to reconstruct the pressure distribution across the entire surface for lift calculations.
Example 7C#
Interpolated Z: 50
.. Admonition:: Example 3 : Reading steam table
In thermodynamics, the properties of water and steam (such as Enthalpy , Entropy , or Specific Volume ) are determined by two independent state variables, typically Pressure () and Temperature ().
these properties are governed by complex non-linear physics, they are often provided in massive, discrete grids known as Steam Tables.When an engineer needs the enthalpy at a specific state that isn't exactly in the table, they must use Bilinear Interpolation (Interp2).
Example 8C#
Specific Volume of superheated water at T = 1350, P = 0.0373 is 20.413475