[Numerical calculation methods (Huang Mingyou)] Function interpolation and curve fitting (2): Cubic Hermite interpolation [Theory to program]


1. Approximate expression

  Interpolation, fitting, and projection are commonly used approximate expressions used to estimate, predict, or represent data or functions.

1. Interpolation

  Refers to estimating or deriving the values ​​between known data points by interpolating between these data points. Interpolation can be used to construct smooth curves or surfaces to make predictions between data points or to supplement missing data.

2. Fitting

  Refers to the process of best fitting a mathematical model to known data points by selecting appropriate functional forms and parameters. The goal of fitting is to find a function whose values ​​near the data points are as close as possible to the actual observed values. Fitting can be used in data analysis, curve fitting, regression analysis and other fields.

3. Projection

  Refers to the process of mapping a vector or a set of vectors to another vector space or subspace. In linear algebra, projection can be used to find the projection or projected components of a vector onto another vector or vector space. Projection can be used in fields such as dimensionality reduction, data compression, and feature extraction, as well as projection transformation in computer graphics.

2. Lagrange interpolation

[Numerical calculation method (Huang Mingyou)] Function interpolation and curve fitting (1): Lagrange interpolation [theory to program]
   Lagrange interpolation is a method used A method of constructing a polynomial function through known data points, Based on the principle of Lagrange interpolation polynomial (the polynomial passes through each data point and satisfies the corresponding condition), Lagrangian interpolation can be used to estimate values ​​between data points, rather than just interpolating at a given data point.

1. Lagrangian interpolation method

  1. Lagrangian basis function: For a given interpolation node x 0 , x 1 , … , x n x_0, x_1, \ ldots, x_n x0,x1,,xn, Lagrangian interpolation uses the following Lagrangian basis function:

    L i ( x ) = ∏ j = 0 , j ≠ i n x − x j x i − x j L_i(x) = \prod_{j=0, j\neq i}^{n} \frac{x - x_j}{x_i - x_j} Li(x)=j=0,j=inxixjxxj

  2. Interpolation condition: Lagrangian interpolation requires the interpolation polynomial to satisfy the interpolation condition: for all i i i P ( x i ) = y i P(x_i) = y_i P(xi)=andi

  3. Interpolation polynomial: Construct the interpolation polynomial as: P ( x ) = ∑ i = 0 n y i L i ( x ) P(x) = \sum_{i=0}^{n} y_i L_i(x) P(x)=i=0nandiLi(x)

  With this method, a smooth interpolation function can be obtained at a given data point, so that the value of the function can be estimated at any position between these data points. Lagrange interpolation may have some problems when there are few data points or there are large gaps between data points. For example, the interpolation polynomial may produce oscillation, which is called theRunge phenomenon.

2. Lagrange interpolation formula

L i ( x ) = ∏ j = 0 , j ≠ i n x − x j x i − x j L_i(x) = \prod_{j=0, j\neq i}^{n} \frac{x - x_j}{x_i - x_j}Li(x)=j=0,j=inxixjxxj P ( x ) = ∑ i = 0 n y i L i ( x ) P(x) = \sum_{i=0}^{n} y_i L_i(x) P(x)=i=0nandiLi(x)

a. Linear interpolation (n=1)

P ( x ) = y 0 ( x − x 1 ) ( x 0 − x 1 ) + y 1 ( x − x 0 ) ( x 1 − x 0 ) P(x) = y_0 \frac{(x - x_1)}{(x_0 - x_1)} + y_1 \frac{(x - x_0)}{(x_1 - x_0)} P(x)=and0(x0x1)(xx1)+and1(x1x0)(xx0)

b. Parabolic interpolation (n=2)

P ( x ) = y 0 ( x − x 1 ) ( x − x 2 ) ( x 0 − x 1 ) ( x 0 − x 2 ) + y 1 ( x − x 0 ) ( x − x 2 ) ( x 1 − x 0 ) ( x 1 − x 2 ) + y 2 ( x − x 0 ) ( x − x 1 ) ( x 2 − x 0 ) ( x 2 − x 1 ) P(x) = y_0 \frac{(x - x_1)(x - x_2)}{(x_0 - x_1)(x_0 - x_2)} + y_1 \frac{(x - x_0)(x - x_2)}{(x_1 - x_0)(x_1 - x_2)} + y_2 \frac{(x - x_0)(x - x_1)}{(x_2 - x_0)(x_2 - x_1)} P(x)=and0(x0x1)(x0x2)(xx1)(xx2)+and1(x1x0)(x1x2)(xx0)(xx2)+and2(x2x0)(x2x1)(xx0)(xx1)

3. Newton interpolation

[Numerical calculation methods (Huang Mingyou)] Function interpolation and curve fitting (2): Newton interpolation [Theory to program]

4. Cubic Hermite interpolation

1. The Book of Heaven

Insert image description here
Insert image description here

Insert image description here
Insert image description here

2. Human language

  We have two interpolation nodes x 0 x_0 x0 sum x 1 x_1 x1, the function values ​​at these nodes are known y 0 = f ( x 0 ) y_0 = f(x_0) and0=f(x0) y 1 = f ( x 1 ) y_1 = f(x_1) and1=f(x1) 和导数值 m 0 = f ′ ( x 0 ) m_0 = f'(x_0) m0=f(x0) m 1 = f ′ ( x 1 ) m_1 = f'(x_1) m1=f(x1). Require a cubic polynomial H ( x ) H(x) H(x),Condition less than full :

  1. H ( x 0 ) = y 0 H(x_0) = y_0 H(x0)=and0,Issues x 0 x_0 x0The function values ​​on the nodes are equal.
  2. H ′ ( x 0 ) = m 0 H'(x_0) = m_0 H(x0)=m0,Immediately x 1 x_1 x1The derivative values ​​at the nodes are equal.
  3. H ( x 1 ) = y 1 H(x_1) = y_1 H(x1)=and1,Immediately x 1 x_1 x1The function values ​​on the nodes are equal.
  4. H ′ ( x 1 ) = m 1 H'(x_1) = m_1 H(x1)=m1,Immediately x 1 x_1 x1The derivative values ​​at the nodes are equal.

Such an interpolation problem can be solved by constructing a cubic polynomial H ( x ) H(x) H(x) to solve. Generally speaking, the basic form of Hermite interpolation is:

H ( x ) = h 0 ( x ) y 0 + h 1 ( x ) m 0 + h 2 ( x ) y 1 + h 3 ( x ) m 1 H(x) = h_0(x) y_0 + h_1(x) m_0 + h_2(x) y_1 + h_3(x) m_1 H(x)=h0(x)y0+h1(x)m0+h2(x)y1+h3(x)m1

  Inside h 0 ( x ) , h 1 ( x ) , h 2 ( x ) , h 3 ( x ) h_0(x), h_1(x), h_2( x), h_3(x) h0(x),h1(x),h2(x),h3(x) is a set of basis functions whose form can be passed through the derivative conditions of the requirements to make sure. Since we need to satisfy the conditions of function value and first-order derivative value, the form of the basis function can be obtained by the derivative of the Lagrange interpolation polynomial.

To be improved...

3. Example questions

Insert image description here

4. python implementation

def hermite_interpolation(x, y, m, xi):
    """
    三次 Hermite 插值

    Parameters:
    - x: 插值节点的 x 坐标
    - y: 插值节点的函数值
    - m: 插值节点的一阶导数值
    - xi: 要进行插值的点的 x 坐标

    Returns:
    - interpolated_value: 在 xi 处的插值结果
    """
    t = (xi - x[0]) / (x[1] - x[0])

    h0 = (1 - 3 * t**2 + 2 * t**3)
    h1 = t * (1 - t)**2
    h2 = xi * (1 - t)**2
    h3 = xi**2 * (3 - 2 * t)

    interpolated_value = h0 * y[0] + h1 * y[1] + h2 * m[0] + h3 * m[1]

    return interpolated_value


# 示例数据
x_nodes = [1, 2]
y_values = [2, 3]
derivatives = [1, 2]
xi_value = 1.5

# 进行三次 Hermite 插值
interpolated_result = hermite_interpolation(x_nodes, y_values, derivatives, xi_value)

# 打印插值结果
print("插值结果:", interpolated_result)

Output:

插值结果: 10.75

Guess you like

Origin blog.csdn.net/m0_63834988/article/details/134915332