zoukankan      html  css  js  c++  java
  • 转载:Cubic interpolation

    https://www.paulinternet.nl/?page=bicubic

    Cubic interpolation

    If the values of a function f(x) and its derivative are known at x=0 and x=1, then the function can be interpolated on the interval [0,1] using a third degree polynomial. This is called cubic interpolation. The formula of this polynomial can be easily derived.

    A third degree polynomial and its derivative:

    f(x) = ax^3 + bx^2 + cx + d

    f'(x) = 3ax^2 + 2bx + c

    The values of the polynomial and its derivative at x=0 and x=1:

    f(0) = d

    f(1) = a + b + c + d

    f'(0) = c

    f'(1) = 3a + 2b + c

    The four equations above can be rewritten to this:

    a = 2f(0) - 2f(1) + f'(0) + f'(1)

    b = -3f(0) + 3f(1) - 2f'(0) - f'(1)

    c = f'(0)

    d = f(0)

    And there we have our cubic interpolation formula.

    Interpolation is often used to interpolate between a list of values. In that case we don't know the derivative of the function. We could simply use derivative 0 at every point, but we obtain smoother curves when we use the slope of a line between the previous and the next point as the derivative at a point. In that case the resulting polynomial is called a Catmull-Rom spline. Suppose you have the values p0, p1, p2and p3 at respectively x=-1, x=0, x=1, and x=2. Then we can assign the values of f(0), f(1), f'(0) and f'(1) using the formulas below to interpolate between p1 and p2.

    f(0) = p_1

    f(1) = p_2

    f'(0) = dfrac{p_2 - p_0}{2}

    f'(1) = dfrac{p_3 - p_1}{2}

    Combining the last four formulas and the preceding four, we get:

    a = -	frac{1}{2}p_0 + 	frac{3}{2}p_1 - 	frac{3}{2}p_2 + 	frac{1}{2}p_3

    b = p_0 - 	frac{5}{2}p_1 + 2p_2 - 	frac{1}{2}p_3

    c = -	frac{1}{2}p_0 + 	frac{1}{2}p_2

    d = p_1

    So our cubic interpolation formula becomes:

    f(p_0,p_1,p_2,p_3,x) = (-	frac{1}{2}p_0 + 	frac{3}{2}p_1 - 	frac{3}{2}p_2 + 	frac{1}{2}p_3)x^3 + (p_0 - 	frac{5}{2}p_1 + 2p_2 - 	frac{1}{2}p_3)x^2 + (-	frac{1}{2}p_0 + 	frac{1}{2}p_2)x + p_1

    For example:

    plot


    For the green curve:

    a = -	frac{1}{2}cdot2 + 	frac{3}{2}cdot4 - 	frac{3}{2}cdot2 + 	frac{1}{2}cdot3 = 	frac{7}{2}

    b = 2 - 	frac{5}{2}cdot4 + 2cdot2 - 	frac{1}{2}cdot3 = -	frac{11}{2}

    c = -	frac{1}{2}cdot2 + 	frac{1}{2}cdot2 = 0

    d = 4

    f(x) = 	frac{7}{2}(x-2)^3 - 	frac{11}{2}(x-2)^2 + 4

    The first and the last interval

    We used the two points left of the interval and the two points right of the inverval as inputs for the interpolation function. But what if we want to interpolate between the first two or last two elements of a list? Then we have no p0 or no p3. The solution is to imagine an extra point at each end of the list. In other words, we have to make up a value for p0 and p3 when interpolating the leftmost and rightmost interval respectively. Two ways to do this are:

      • Repeat the first and the last point.
        Left: p0 = p1
        Right: p3 = p2
      • Let the end point be in the middle of a line between the imaginary point and the point next to the end point.
        Left: p0 = 2p1 - p2
        Right: p3 = 2p2 - p1
  • 相关阅读:
    java excel转pdf 工具类
    java word转pdf 工具类
    如何向数据库中添加TIMESTAMP(6)类型的数据
    IE浏览器 div或者其他容器的height属性无效 滚动条问题解决办法
    ComboBox赋值ItemsSource数据源的时候会触发SelectionChanged改变事件的解决办法
    devexpress chart 散点图加载并分组显示(可以自定义颜色 同组中的点颜色相同)
    myEclipse mybatis自动生成工具xml配置
    MySQL日志简介
    存储引擎简介
    索引介绍
  • 原文地址:https://www.cnblogs.com/fellow1988/p/9992026.html
Copyright © 2011-2022 走看看