예제 #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))
예제 #2
0
파일: nodes.py 프로젝트: memmett/PyIPM
def clenshaw_curtis_nodes(n):
  """Return Clenshaw-Curtis nodes (actually returns n+1 nodes)."""

  r = set()
  for k in range(n+1):
    r.add(mpmath.cos(k*mpmath.pi/mpmath.mpf(n)))

  return sorted(r)
예제 #3
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))
예제 #4
0
파일: sdcquad.py 프로젝트: dasmy/sdcquad
def clenshaw_curtis_nodes(n):
  """Return Clenshaw-Curtis nodes."""

  r = set()
  for i in range(n):
    r.add(mpmath.cos(i*mpmath.pi/mpmath.mpf(n-1)))

  return map_to_zero_one(r)
예제 #5
0
def test_odefun_sinc_large():
    mp.dps = 15
    # Sinc function; test for large x
    f = sinc
    g = odefun(lambda x, y: [(cos(x) - y[0]) / x],
               1, [f(1)],
               tol=0.01,
               degree=5)
    assert abs(f(100) - g(100)[0]) / f(100) < 0.01
예제 #6
0
파일: nodes.py 프로젝트: memmett/PyIPM
def clenshaw_curtis_weights(n):
  """Return Clenshaw-Curtis weights (actually the n+1 weights)."""

  w = []
  for k in range(n+1):
    c_k = 1.0 if k % n == 0 else 2.0
    t_k = k*mpmath.pi/mpmath.mpf(n)

    acc = 1.0
    for j in range(1, n/2+1):
      b_j = 2.0 if j < n/2 else 1.0
      acc -= b_j / (4.0*j**2 - 1.0) * mpmath.cos(2*j*t_k)

    w.append(c_k / n * acc)

  return w
 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."
예제 #8
0
def test_odefun_sinc_large():
    mp.dps = 15
    # Sinc function; test for large x
    f = sinc
    g = odefun(lambda x, y: [(cos(x)-y[0])/x], 1, [f(1)], tol=0.01, degree=5)
    assert abs(f(100) - g(100)[0])/f(100) < 0.01
예제 #9
0
 def pi_inner_integral(y):
     vardict = {'y': y}
     out = maple_link.eval_stack(pi_stack, vardict)
     return out * cos(int(j) * y)
예제 #10
0
 def pi_inner_integral(y):
     vardict = {'y':y}
     out = maple_link.eval_stack(pi_stack, vardict)
     return out*cos(int(j)*y)
 def f(x):
     return d_polynomial(x, list_a) - sm.cos(x)
예제 #12
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."
예제 #13
0
 def f(x):
     return d_polynomial(x, list_a) - sm.cos(x);