Beispiel #1
0
def test_discretize_adaptive():
    x, y = discretize(np.cos, 0, np.pi, method='adaptive')
    assert_allclose(x, [0., 0.19634954, 0.39269908, 0.58904862, 0.78539816,
                        0.9817477, 1.17809725, 1.37444679, 1.57079633, 1.76714587,
                        1.96349541, 2.15984495, 2.35619449, 2.55254403, 2.74889357,
                        2.94524311, 3.14159265])
    assert_allclose(y, [1.00000000e+00, 9.80785280e-01, 9.23879533e-01,
                        8.31469612e-01, 7.07106781e-01, 5.55570233e-01,
                        3.82683432e-01, 1.95090322e-01, 6.12323400e-17,
                        -1.95090322e-01, -3.82683432e-01, -5.55570233e-01,
                        -7.07106781e-01, -8.31469612e-01, -9.23879533e-01,
                        -9.80785280e-01, -1.00000000e+00])
Beispiel #2
0
def test_discretize():
    x, y = discretize(np.cos, 0, np.pi, tol=0.01)
    assert_array_almost_equal(
        x,
        np.array(
            [0., 0.19634954, 0.39269908, 0.58904862, 0.78539816,
             0.9817477, 1.17809725, 1.37444679, 1.57079633, 1.76714587,
             1.96349541, 2.15984495, 2.35619449, 2.55254403, 2.74889357,
             2.94524311, 3.14159265]))
    assert_array_almost_equal(
        y, np.array([1.00000000e+00, 9.80785280e-01,
                     9.23879533e-01,
                     8.31469612e-01, 7.07106781e-01, 5.55570233e-01,
                     3.82683432e-01, 1.95090322e-01, 6.12323400e-17,
                     -1.95090322e-01, -3.82683432e-01, -5.55570233e-01,
                     -7.07106781e-01, -8.31469612e-01, -9.23879533e-01,
                     -9.80785280e-01, -1.00000000e+00]))