cmlabs.interpolate.test_lagrange_degree_2

cmlabs.interpolate.test_lagrange_degree_2()[source]

Calculate Lagrange interpolation polynomial of degree 2 at \(x^*\).

\[L_2(x^*) = f(x_{i-1}) \cdot \frac{(x^* - x_i)(x^* - x_{i+1})}{(x_{i-1} - x_i)(x_i - x_{i+1})} + f(x_i) \cdot \frac{(x^* - x_{i-1})(x^* - x_{i+1})}{(x_i - x_{i-1})(x_i - x_{i+1})} + f(x_{i+1}) \cdot \frac{(x^* - x_{i-1})(x^* - x_i)}{(x_{i+1} - x_{i-1})(x_{i+1} - x_i)}\]

Results

>>> # Test 3: Lagrange Interpolation Of Degree 2
>>> # - f(x) = x - lg(x + 2)
>>> # - X:  [0.5   0.556 0.611 ... 0.889 0.944 1.   ]
>>> # - Y:  [0.102 0.148 0.194 ... 0.428 0.475 0.523]
>>> # - x* =  0.77
>>> f(0.77)
>>> # 0.32752023093555144
>>> # Nearest points: [0.722 0.778 0.833]
>>> # Nearest f(x) values: [0.287 0.334 0.381]
>>> lagrange([0.722 0.778 0.833], [0.287 0.334 0.381], 0.77)
>>> # 0.3275203902670937

See also

lagrange