cmlabs.interpolate.test_lagrange_compare_with_newton
- cmlabs.interpolate.test_lagrange_compare_with_newton(degree)[source]
Compare Lagrange and Newton interpolation.
\[\begin{split}\begin{gather} L_n(x) = \sum_{i=0}^{n} l_i(x) f(x_i)\\ \\ L_n(x) = \sum_{i=0}^{n} f(x_0, x_1, \ldots, x_i) \omega_i(x) \end{gather}\end{split}\]Results
>>> # Test 5: Compare Lagrange And Newton Interpolation Degree 1 >>> # - 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 >>> # Nearest points: [0.722 0.778] >>> # Nearest f(x) values: [0.287 0.334] >>> lagrange([0.722 0.778], [0.287 0.334], 0.77) >>> # 0.327530850170338 >>> newton([0.722 0.778], 0.77, yvals=[0.287 0.334]) >>> # 0.327530850170338
>>> # Test 6: Compare Lagrange And Newton Interpolation Degree 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 >>> # 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 >>> newton([0.722 0.778 0.833], 0.77, yvals=[0.287 0.334 0.381]) >>> # 0.3275203902670936