예제 #1
0
def test_fd_derivative():
    x = np.linspace(-1, 1, 25)
    fx = np.exp(x)
    for n in range(1, 7):
        df = fd_derivative(fx, x, n=n)
        m = n // 2 + 2
        np.testing.assert_allclose(df[m:-m], fx[m:-m], atol=1e-5)
        np.testing.assert_allclose(df[-m:], fx[-m:], atol=1e-4)
        np.testing.assert_allclose(df[:m], fx[:m], atol=1e-4)
예제 #2
0
 def test_fd_derivative():
     x = np.linspace(-1, 1, 25)
     h = np.diff(x).mean()
     fx = np.exp(x)
     for n in range(1, 7):
         df = fd_derivative(fx, x, n=n)
         m = n // 2 + 2
         np.testing.assert_allclose(df[m:-m], fx[m:-m], atol=1e-5)
         np.testing.assert_allclose(df[-m:], fx[-m:], atol=1e-4)
         np.testing.assert_allclose(df[:m], fx[:m], atol=1e-4)