示例#1
0
def test_complex_to_real_jac():
    z = np.array([[1 + 2j]])
    r = _complex_to_real_jac(z)
    yield assert_array_equal, r, np.array([[1, -2], [2, 1]])
    z = np.array([[1 + 2j, 3 + 4j], [5 + 6j, 7 + 8j]])
    r = _complex_to_real_jac(z)
    expected = np.array([[1, -2, 3, -4], [2, 1, 4, 3], [5, -6, 7, -8],
                         [6, 5, 8, 7]])
    yield assert_array_equal, r, expected
示例#2
0
def test_complex_to_real_jac():
    z = np.array([[1+2j]])
    r = _complex_to_real_jac(z)
    yield assert_array_equal, r, np.array([[1, -2], [2, 1]])
    z = np.array([[1+2j, 3+4j],
                  [5+6j, 7+8j]])
    r = _complex_to_real_jac(z)
    expected = np.array([[1, -2, 3, -4],
                         [2,  1, 4,  3],
                         [5, -6, 7, -8],
                         [6,  5, 8,  7]])
    yield assert_array_equal, r, expected
示例#3
0
def funcz(y, t, c):
    # Same calculation as `func`, but computed using real arrays,
    # so the calculation in `dot` should follow the same code path
    # for both the real and complex examples below.
    creal = _complex_to_real_jac(c)
    dydt = creal.dot(y.view(np.float64))
    return dydt.view(np.complex128)
示例#4
0
def system3_funcz(y, t, c):
    # Same calculation as `system3_func`, but computed using real arrays,
    # so the calculation in `dot` should follow the same code path for
    # both the real and complex examples below.
    creal = _complex_to_real_jac(c)
    dydt = creal.dot(y.view(np.float64))
    return dydt.view(np.complex128)
示例#5
0
def test_system3():
    c = np.array([[-20+1j, 5-1j,      0,       0], 
                  [     0, -0.1,  1+2.5j,      0],
                  [     0,    0,      -1,    0.5],
                  [     0,    0,       0,  -5+10j]])

    z0 = np.arange(1,5.0) + 0.5j

    t = np.linspace(0, 250, 11)

    common_kwargs = dict(full_output=True, atol=1e-12, rtol=1e-10,
                         mxstep=1000)

    sol0, info0 = odeintw(system3_funcz, z0, t, Dfun=system3_jac,
                          args=(c,), **common_kwargs)
    nje0 = info0['nje']

    x0 = z0.view(np.float64)
    sol1, info1 = odeint(system3_func, x0, t, Dfun=system3_jac,
                         args=(_complex_to_real_jac(c),), **common_kwargs)
    nje1 = info1['nje']

    # Using assert_array_equal here is risky.  The system definitions have
    # been defined so the call to odeint in odeintw follows the same
    # code path as the call to odeint above.  Still, floating point operations
    # aren't necessarily deterministic.
    yield assert_array_equal, sol0.view(np.float64), sol1
    yield assert_array_equal, nje0, nje1
示例#6
0
def test_system3():
    c = np.array([[-20 + 1j, 5 - 1j, 0, 0], [0, -0.1, 1 + 2.5j, 0],
                  [0, 0, -1, 0.5], [0, 0, 0, -5 + 10j]])

    z0 = np.arange(1, 5.0) + 0.5j

    t = np.linspace(0, 250, 11)

    common_kwargs = dict(full_output=True, atol=1e-12, rtol=1e-10, mxstep=1000)

    sol0, info0 = odeintw(system3_funcz,
                          z0,
                          t,
                          Dfun=system3_jac,
                          args=(c, ),
                          **common_kwargs)
    nje0 = info0['nje']

    x0 = z0.view(np.float64)
    sol1, info1 = odeint(system3_func,
                         x0,
                         t,
                         Dfun=system3_jac,
                         args=(_complex_to_real_jac(c), ),
                         **common_kwargs)
    nje1 = info1['nje']

    # Using assert_array_equal here is risky.  The system definitions have
    # been defined so the call to odeint in odeintw follows the same
    # code path as the call to odeint above.  Still, floating point operations
    # aren't necessarily deterministic.
    yield assert_array_equal, sol0.view(np.float64), sol1
    yield assert_array_equal, nje0, nje1
示例#7
0
                     atol=1e-12,
                     rtol=1e-10,
                     mxstep=1000)

sol0, info0 = odeintw(funcz, z0, t, Dfun=jac, **common_kwargs)
print(info0['nje'])

rargs = common_kwargs.copy()
rargs.pop('args')

x0 = z0.view(np.float64)
solr, infor = odeint(func,
                     x0,
                     t,
                     Dfun=jac,
                     args=(_complex_to_real_jac(c), ),
                     **rargs)
print(infor['nje'])

print("-----")

solbnj, infobnj = odeintw(func, z0, t, ml=0, mu=1, **common_kwargs)
print(infobnj['nje'])

sol2, info2 = odeint(func,
                     x0,
                     t,
                     ml=1,
                     mu=3,
                     args=(_complex_to_real_jac(c), ),
                     **rargs)
示例#8
0
print()

z0 = np.arange(1,5.0) + 0.5j

t = np.linspace(0, 250, 11)

common_kwargs = dict(args=(c,), full_output=True, atol=1e-12, rtol=1e-10, mxstep=1000)

sol0, info0 = odeintw(funcz, z0, t, Dfun=jac, **common_kwargs)
print(info0['nje'])

rargs = common_kwargs.copy()
rargs.pop('args')

x0 = z0.view(np.float64)
solr, infor = odeint(func, x0, t, Dfun=jac, args=(_complex_to_real_jac(c),), **rargs)
print(infor['nje'])

print("-----")

solbnj, infobnj = odeintw(func, z0, t, ml=0, mu=1, **common_kwargs)
print(infobnj['nje'])

sol2, info2 = odeint(func, x0, t, ml=1, mu=3, args=(_complex_to_real_jac(c),), **rargs)
print(info2['nje'])

print("-----")

sol1, info1 = odeintw(func, z0, t, Dfun=bjac_cols, ml=0, mu=1, col_deriv=True, **common_kwargs)
print(info1['nje'])
common_kwargs = dict(args=(c,),
                     full_output=True,
                     atol=1e-12,
                     rtol=1e-10,
                     mxstep=1000)

sol0, info0 = odeintw(funcz, z0, t, Dfun=jac, **common_kwargs)
print(info0['nje'])

rargs = common_kwargs.copy()
rargs.pop('args')

x0 = z0.view(np.float64)
solr, infor = odeint(func, x0, t, Dfun=jac,
                     args=(_complex_to_real_jac(c),), **rargs)
print(infor['nje'])

print("-----")

solbnj, infobnj = odeintw(func, z0, t, ml=0, mu=1, **common_kwargs)
print(infobnj['nje'])

sol2, info2 = odeint(func, x0, t, ml=1, mu=3,
                     args=(_complex_to_real_jac(c),), **rargs)
print(info2['nje'])

print("-----")

sol1, info1 = odeintw(func, z0, t, Dfun=bjac_cols, ml=0, mu=1,
                      col_deriv=True, **common_kwargs)