Exemplo n.º 1
0
def test_odefun_harmonic():
    mp.dps = 15
    # Harmonic oscillator
    f = odefun(lambda x, y: [-y[1], y[0]], 0, [1, 0])
    for x in [0, 1, 2.5, 8, 3.7]:  #  we go back to 3.7 to check caching
        c, s = f(x)
        assert c.ae(cos(x))
        assert s.ae(sin(x))
Exemplo n.º 2
0
def test_odefun_harmonic():
    mp.dps = 15
    # Harmonic oscillator
    f = odefun(lambda x, y: [-y[1], y[0]], 0, [1, 0])
    for x in [0, 1, 2.5, 8, 3.7]:    #  we go back to 3.7 to check caching
        c, s = f(x)
        assert c.ae(cos(x))
        assert s.ae(sin(x))
def update_polynomial_coefficients(list_x):
    matrix_A = sm.matrix(
        [[x**k for k in range(len(list_x)-1)] + [ 0 if j==0 else (-1)**j ]  \
               for j,x in enumerate(list_x)])

    vector_b = sm.matrix([sm.sin(x) for x in list_x])

    u = sm.lu_solve(matrix_A, vector_b)

    # a[0],...,a[n], d
    return u[:-1], u[u.rows - 1]
Exemplo n.º 4
0
def update_polynomial_coefficients(list_x):
    matrix_A = sm.matrix(
        [[x**k for k in range(len(list_x)-1)] + [ 0 if j==0 else (-1)**j ]  \
               for j,x in enumerate(list_x)])

    vector_b = sm.matrix([sm.sin(x) for x in list_x])

    u = sm.lu_solve(matrix_A, vector_b)

    # a[0],...,a[n], d
    return u[:-1], u[u.rows-1]
 p = np.poly1d([1, 0, 0, 0, 1])
 # use mayavi if possible.
 # otherwise, fall back to matplotlib.
 if use_mayavi:
     plot_both_mayavi(p)
     nroot_real_mayavi(5)
     nroot_imag_mayavi(5)
 else:
     plot_both_matplotlib(p)
     nroot_real_matplotlib(5)
     nroot_imag_matplotlib(5)
 
 # All the different integration examples.
 f1 = lambda z: z.conjugate()
 f2 = lambda z: mp.exp(z)
 c1 = lambda t: mp.cos(t) + 1.0j * mp.sin(t)
 c2 = lambda t: t + 1.0j * t
 c3 = lambda t: t
 c4 = lambda t: 1 + 1.0j * t
 c5 = lambda t: mp.cos(t) + 1.0j + 1.0j * mp.sin(t)
 print "z conjugate counterclockwise along the unit ball starting and ending at 1."
 print contour_int(f1, c1, 0, 2 * np.pi)
 print "z conjugate along a straight line from 0 to 1+1j."
 print contour_int(f1, c2, 0, 1)
 print "z conjugate along the real axis from 0 to 1, then along the line from 1 to 1+1j."
 print contour_int(f1, c3, 0, 1) + contour_int(f1, c4, 0, 1)
 print "z conjugate along the unit ball centered at 1j from 0 to 1+1j."
 print contour_int(f1, c5, -np.pi / 2, 0.)
 print "e^z counterclockwise along the unit ball starting and ending at 1."
 print contour_int(f2, c1, 0, 2 * np.pi)
 print "e^z along a straight line from 0 to 1+1j."
 def ef(x):
     return polynomial(x, list_a) - sm.sin(x)
 def df(x):
     return dd_polynomial(x, list_a) + sm.sin(x)
Exemplo n.º 8
0
    p = np.poly1d([1, 0, 0, 0, 1])
    # use mayavi if possible.
    # otherwise, fall back to matplotlib.
    if use_mayavi:
        plot_both_mayavi(p)
        nroot_real_mayavi(5)
        nroot_imag_mayavi(5)
    else:
        plot_both_matplotlib(p)
        nroot_real_matplotlib(5)
        nroot_imag_matplotlib(5)

    # All the different integration examples.
    f1 = lambda z: z.conjugate()
    f2 = lambda z: mp.exp(z)
    c1 = lambda t: mp.cos(t) + 1.0j * mp.sin(t)
    c2 = lambda t: t + 1.0j * t
    c3 = lambda t: t
    c4 = lambda t: 1 + 1.0j * t
    c5 = lambda t: mp.cos(t) + 1.0j + 1.0j * mp.sin(t)
    print "z conjugate counterclockwise along the unit ball starting and ending at 1."
    print contour_int(f1, c1, 0, 2 * np.pi)
    print "z conjugate along a straight line from 0 to 1+1j."
    print contour_int(f1, c2, 0, 1)
    print "z conjugate along the real axis from 0 to 1, then along the line from 1 to 1+1j."
    print contour_int(f1, c3, 0, 1) + contour_int(f1, c4, 0, 1)
    print "z conjugate along the unit ball centered at 1j from 0 to 1+1j."
    print contour_int(f1, c5, -np.pi / 2, 0.)
    print "e^z counterclockwise along the unit ball starting and ending at 1."
    print contour_int(f2, c1, 0, 2 * np.pi)
    print "e^z along a straight line from 0 to 1+1j."
Exemplo n.º 9
0
 def ef(x):
     return polynomial(x, list_a) - sm.sin(x)
Exemplo n.º 10
0
 def df(x):
     return dd_polynomial(x, list_a) + sm.sin(x);