(x_array, *testcases)
| 298 | return (y1 - y0) / (2.0 * eps) |
| 299 | |
| 300 | def test(x_array, *testcases): |
| 301 | for f in testcases: |
| 302 | print(f.__name__.center(40)) |
| 303 | print('-' * 40) |
| 304 | for x in map(Var, x_array): |
| 305 | y = f(x) |
| 306 | actual = d(y) |
| 307 | expected = numeric_derivative(f, x, 2**-16) |
| 308 | print('%7.3f %12.4f %12.4f' % (x, actual, expected)) |
| 309 | assert math.isclose(expected, actual, rel_tol=1e-5) |
| 310 | print('') |
| 311 | |
| 312 | def test_pow_const_base(x): |
| 313 | return 3.1 ** (2.3 * x + 0.4) |
no test coverage detected