Fit coefficients for 4th order polynomial interpolation. Args: y0: function value at the start of the interval. y1: function value at the end of the interval. y_mid: function value at the mid-point of the interval. f0: derivative value at the start of the interval. f1: derivat
(y0, y1, y_mid, f0, f1, dt)
| 134 | |
| 135 | |
| 136 | def _interp_fit(y0, y1, y_mid, f0, f1, dt): |
| 137 | """Fit coefficients for 4th order polynomial interpolation. |
| 138 | |
| 139 | Args: |
| 140 | y0: function value at the start of the interval. |
| 141 | y1: function value at the end of the interval. |
| 142 | y_mid: function value at the mid-point of the interval. |
| 143 | f0: derivative value at the start of the interval. |
| 144 | f1: derivative value at the end of the interval. |
| 145 | dt: width of the interval. |
| 146 | |
| 147 | Returns: |
| 148 | List of coefficients `[a, b, c, d, e]` for interpolating with the polynomial |
| 149 | `p = a * x ** 4 + b * x ** 3 + c * x ** 2 + d * x + e` for values of `x` |
| 150 | between 0 (start of interval) and 1 (end of interval). |
| 151 | """ |
| 152 | # a, b, c, d, e = sympy.symbols('a b c d e') |
| 153 | # x, dt, y0, y1, y_mid, f0, f1 = sympy.symbols('x dt y0 y1 y_mid f0 f1') |
| 154 | # p = a * x ** 4 + b * x ** 3 + c * x ** 2 + d * x + e |
| 155 | # sympy.solve([p.subs(x, 0) - y0, |
| 156 | # p.subs(x, 1 / 2) - y_mid, |
| 157 | # p.subs(x, 1) - y1, |
| 158 | # (p.diff(x) / dt).subs(x, 0) - f0, |
| 159 | # (p.diff(x) / dt).subs(x, 1) - f1], |
| 160 | # [a, b, c, d, e]) |
| 161 | # {a: -2.0*dt*f0 + 2.0*dt*f1 - 8.0*y0 - 8.0*y1 + 16.0*y_mid, |
| 162 | # b: 5.0*dt*f0 - 3.0*dt*f1 + 18.0*y0 + 14.0*y1 - 32.0*y_mid, |
| 163 | # c: -4.0*dt*f0 + dt*f1 - 11.0*y0 - 5.0*y1 + 16.0*y_mid, |
| 164 | # d: dt*f0, |
| 165 | # e: y0} |
| 166 | a = _dot_product([-2 * dt, 2 * dt, -8, -8, 16], [f0, f1, y0, y1, y_mid]) |
| 167 | b = _dot_product([5 * dt, -3 * dt, 18, 14, -32], [f0, f1, y0, y1, y_mid]) |
| 168 | c = _dot_product([-4 * dt, dt, -11, -5, 16], [f0, f1, y0, y1, y_mid]) |
| 169 | d = dt * f0 |
| 170 | e = y0 |
| 171 | return [a, b, c, d, e] |
| 172 | |
| 173 | |
| 174 | def _interp_fit_rk(y0, y1, k, dt, tableau=_DORMAND_PRINCE_TABLEAU): |
no test coverage detected