Interpolation: Difference between revisions

From Met Dynamics
Jump to navigation Jump to search
md>Scott.Munro
(Created page with "== Description == This article describes '''linear''' and '''cubic spline''' data interpolation methods. == Model theory == {{Under construction|section}} == Excel == {{U...")
 
imported>Scott.Munro
 
(5 intermediate revisions by 3 users not shown)
Line 5: Line 5:
== Model theory ==
== Model theory ==


{{Under construction|section}}
[[File:Interpolation2.png|thumb|425px|Figure 1. An example of cubic spline interpolation with linear extrapolation at the extents. The spline shown is non-monotonic.]]
 
=== Linear interpolation ===
 
Linear interpolation is a technique for approximating the value of a function between two known data points. It involves constructing a straight line that passes through the two given points and using this line to estimate the value of the function at an intermediate point.
 
Given two data points <math>(x_1, y_1)</math> and <math>(x_2, y_2)</math>, where <math>x_1 < x_2</math>, the linear interpolation formula to estimate the value <math>y</math> at a point <math>x</math> within the interval <math>(x_1, x_2)</math> is:
 
:<math>y = y_1 + \frac{x - x_1}{x_2 - x_1} (y_2 - y_1)</math>
 
Linear interpolation provides a simple and computationally efficient method for approximating function values.
 
=== Cubic spline interpolation ===
 
Cubic spline interpolation uses a piecewise cubic polynomial to approximate a function smoothly between known data points.
 
Given a set of distinct data points <math>(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)</math>, where <math>x_1<x_2< \dots < x_n</math>, a cubic spline interpolator constructs a piecewise cubic polynomial <math>S(x)</math> that satisfies the following conditions:
# Interpolation: <math>S(x_i) = y_i</math> for <math>i=1,2,\dots,n</math>. (The spline passes through all data points).
# Smoothness: <math>S(x)</math> and its first two derivatives are continuous across the entire interval <math>[x_1, x_n]</math>. (The spline has no abrupt changes in its slope or curvature).
 
Cubic splines offer enhanced accuracy and flexibility compared to linear interpolation, especially for functions with nonlinear behavior.
 
The following features are also applied for this implementation of cubic splines:
* Linear extrapolation at the extents of the data set, as illustrated in Figure 1, and
* Monotonicity of the spline may be optionally enforced.
 
Please see the Wikipedia articles on [[wikipedia:Spline interpolation|Spline interpolation]] and [[wikipedia:Monotone cubic interpolation|Monotone cubic interpolation]], or references such as Napier-Munn et al. (1996) for a more detailed description of cubic spline interpolation.{{Napier-Munn et al. (1996)}}


== Excel ==
== Excel ==
{{Under construction|section}}


The interpolation methods may be invoked from the Excel formula bar with the following function calls:
The interpolation methods may be invoked from the Excel formula bar with the following function calls:


<syntaxhighlight lang="vb">=mdInterp_Linear(known_xs as Range, known_ys as Range, xs as Range)</syntaxhighlight>
<syntaxhighlight lang="vb">=mdInterp_Linear(known_xs as Range, known_ys as Range, xs as Range)</syntaxhighlight>
<syntaxhighlight lang="vb">=mdInterp_CubicSpline(known_xs as Range, known_ys as Range, xs as Range)</syntaxhighlight>
 
and
 
<syntaxhighlight lang="vb">=mdInterp_CubicSpline(known_xs as Range, known_ys as Range, xs as Range, Optional monotonic as Boolean = false)</syntaxhighlight>


{{Excel (Text, Help, No Arguments)}}
{{Excel (Text, Help, No Arguments)}}
The input parameters and calculation results are defined below in matrix notation, along with an example image showing the selection of the same cells and arrays in the Excel interface:
{|
|- style="vertical-align:top;"
|
{|
  |- style="vertical-align:top;"
  |
:<math>
  \begin{align}
  \mathit{known\_xs}  =
\begin{bmatrix}
x_1\\
\vdots\\
x_n\\
\end{bmatrix},\;\;\;\;
  \mathit{known\_ys}  =
\begin{bmatrix}
y_1\\
\vdots\\
y_n\\
\end{bmatrix},\;\;\;\;
  \mathit{xs}  =
\begin{bmatrix}
x_1\\
\vdots\\
x_m\\
\end{bmatrix}\;\;\;\;
  \end{align}</math>
  |<math>
\begin{align}
  \mathit{mdInterp\_Linear}  & = 
\begin{bmatrix}
y_1\\
\vdots\\
y_m\\
\end{bmatrix}\\
\\
  \mathit{mdInterp\_CubicSpline} & = 
\begin{bmatrix}
y_1\\
\vdots\\
y_m\\
\end{bmatrix}
\end{align}
</math>
  |-  style="vertical-align:top;"
  |colspan="2"|
where:
* <math>n</math> is the number of data points
* <math>m</math> is the number of interpolation points
* <math>x_1 \cdots x_n</math> is an array of the known independent data values
* <math>y_1 \cdots y_n</math> is an array of the known dependent data values
* <math>x_1 \cdots x_m</math> is an array of the independent data values at which the dependant variable is to be interpolated
* <math>y_1 \cdots y_m</math> is an array of the interpolated dependant variable values
  |}
|
::[[File:Interpolation1.png|frame|Figure 1. Example showing the selection of the '''known_xs''' (blue frame), '''known_ys''' (red frame), '''xs''' (purple frame), and '''Results''' (light blue frame) arrays in Excel.]]
|}


== References ==
== References ==


[[Category:Excel]]
[[Category:Excel]]

Latest revision as of 08:57, 22 June 2024

Description

This article describes linear and cubic spline data interpolation methods.

Model theory

Figure 1. An example of cubic spline interpolation with linear extrapolation at the extents. The spline shown is non-monotonic.

Linear interpolation

Linear interpolation is a technique for approximating the value of a function between two known data points. It involves constructing a straight line that passes through the two given points and using this line to estimate the value of the function at an intermediate point.

Given two data points and , where , the linear interpolation formula to estimate the value at a point within the interval is:

Linear interpolation provides a simple and computationally efficient method for approximating function values.

Cubic spline interpolation

Cubic spline interpolation uses a piecewise cubic polynomial to approximate a function smoothly between known data points.

Given a set of distinct data points , where , a cubic spline interpolator constructs a piecewise cubic polynomial that satisfies the following conditions:

  1. Interpolation: for . (The spline passes through all data points).
  2. Smoothness: and its first two derivatives are continuous across the entire interval . (The spline has no abrupt changes in its slope or curvature).

Cubic splines offer enhanced accuracy and flexibility compared to linear interpolation, especially for functions with nonlinear behavior.

The following features are also applied for this implementation of cubic splines:

  • Linear extrapolation at the extents of the data set, as illustrated in Figure 1, and
  • Monotonicity of the spline may be optionally enforced.

Please see the Wikipedia articles on Spline interpolation and Monotone cubic interpolation, or references such as Napier-Munn et al. (1996) for a more detailed description of cubic spline interpolation.[1]

Excel

The interpolation methods may be invoked from the Excel formula bar with the following function calls:

=mdInterp_Linear(known_xs as Range, known_ys as Range, xs as Range)

and

=mdInterp_CubicSpline(known_xs as Range, known_ys as Range, xs as Range, Optional monotonic as Boolean = false)

Invoking the function with no arguments will print Help text associated with the model, including a link to this page.

The input parameters and calculation results are defined below in matrix notation, along with an example image showing the selection of the same cells and arrays in the Excel interface:

where:

  • is the number of data points
  • is the number of interpolation points
  • is an array of the known independent data values
  • is an array of the known dependent data values
  • is an array of the independent data values at which the dependant variable is to be interpolated
  • is an array of the interpolated dependant variable values
Figure 1. Example showing the selection of the known_xs (blue frame), known_ys (red frame), xs (purple frame), and Results (light blue frame) arrays in Excel.

References

  1. Napier-Munn, T.J., Morrell, S., Morrison, R.D. and Kojovic, T., 1996. Mineral comminution circuits: their operation and optimisation. Julius Kruttschnitt Mineral Research Centre, Indooroopilly, QLD.