def ploteig(an,ev,nd=20): N = len(an) x = linspace(-1, 1, nd) v = zeros(nd, float) for i, a in enumerate(an): T = orthogonal.chebyt(2*i) v[:] += a*T(x) plot(x, v, 'o-') return x, v
def test_t_roots(): weightf = orth.chebyt(5).weight_func verify_gauss_quad(orth.t_roots, orth.eval_chebyt, weightf, -1., 1., 5) verify_gauss_quad(orth.t_roots, orth.eval_chebyt, weightf, -1., 1., 25) verify_gauss_quad(orth.t_roots, orth.eval_chebyt, weightf, -1., 1., 100) x, w = orth.t_roots(5, False) y, v, m = orth.t_roots(5, True) assert_allclose(x, y, 1e-14, 1e-14) assert_allclose(w, v, 1e-14, 1e-14) muI, muI_err = integrate.quad(weightf, -1, 1) assert_allclose(m, muI, rtol=muI_err) assert_raises(ValueError, orth.t_roots, 0) assert_raises(ValueError, orth.t_roots, 3.3)
def test_roots_chebyt(): weightf = orth.chebyt(5).weight_func verify_gauss_quad(sc.roots_chebyt, orth.eval_chebyt, weightf, -1., 1., 5) verify_gauss_quad(sc.roots_chebyt, orth.eval_chebyt, weightf, -1., 1., 25) verify_gauss_quad(sc.roots_chebyt, orth.eval_chebyt, weightf, -1., 1., 100) x, w = sc.roots_chebyt(5, False) y, v, m = sc.roots_chebyt(5, True) assert_allclose(x, y, 1e-14, 1e-14) assert_allclose(w, v, 1e-14, 1e-14) muI, muI_err = integrate.quad(weightf, -1, 1) assert_allclose(m, muI, rtol=muI_err) assert_raises(ValueError, sc.roots_chebyt, 0) assert_raises(ValueError, sc.roots_chebyt, 3.3)
def test_chebyt(self): T0 = orth.chebyt(0) T1 = orth.chebyt(1) T2 = orth.chebyt(2) T3 = orth.chebyt(3) T4 = orth.chebyt(4) T5 = orth.chebyt(5) assert_array_almost_equal(T0.c, [1], 13) assert_array_almost_equal(T1.c, [1, 0], 13) assert_array_almost_equal(T2.c, [2, 0, -1], 13) assert_array_almost_equal(T3.c, [4, 0, -3, 0], 13) assert_array_almost_equal(T4.c, [8, 0, -8, 0, 1], 13) assert_array_almost_equal(T5.c, [16, 0, -20, 0, 5, 0], 13)
def test_chebyt(self): T0 = orth.chebyt(0) T1 = orth.chebyt(1) T2 = orth.chebyt(2) T3 = orth.chebyt(3) T4 = orth.chebyt(4) T5 = orth.chebyt(5) assert_array_almost_equal(T0.c,[1],13) assert_array_almost_equal(T1.c,[1,0],13) assert_array_almost_equal(T2.c,[2,0,-1],13) assert_array_almost_equal(T3.c,[4,0,-3,0],13) assert_array_almost_equal(T4.c,[8,0,-8,0,1],13) assert_array_almost_equal(T5.c,[16,0,-20,0,5,0],13)
def test_sh_chebyt(self): # T*_n(x) = T_n(2x-1) psub = np.poly1d([2, -1]) Ts0 = orth.sh_chebyt(0) Ts1 = orth.sh_chebyt(1) Ts2 = orth.sh_chebyt(2) Ts3 = orth.sh_chebyt(3) Ts4 = orth.sh_chebyt(4) Ts5 = orth.sh_chebyt(5) tse0 = orth.chebyt(0)(psub) tse1 = orth.chebyt(1)(psub) tse2 = orth.chebyt(2)(psub) tse3 = orth.chebyt(3)(psub) tse4 = orth.chebyt(4)(psub) tse5 = orth.chebyt(5)(psub) assert_array_almost_equal(Ts0.c, tse0.c, 13) assert_array_almost_equal(Ts1.c, tse1.c, 13) assert_array_almost_equal(Ts2.c, tse2.c, 13) assert_array_almost_equal(Ts3.c, tse3.c, 13) assert_array_almost_equal(Ts4.c, tse4.c, 12) assert_array_almost_equal(Ts5.c, tse5.c, 12)
def test_sh_chebyt(self): # T*_n(x) = T_n(2x-1) psub = np.poly1d([2,-1]) Ts0 = orth.sh_chebyt(0) Ts1 = orth.sh_chebyt(1) Ts2 = orth.sh_chebyt(2) Ts3 = orth.sh_chebyt(3) Ts4 = orth.sh_chebyt(4) Ts5 = orth.sh_chebyt(5) tse0 = orth.chebyt(0)(psub) tse1 = orth.chebyt(1)(psub) tse2 = orth.chebyt(2)(psub) tse3 = orth.chebyt(3)(psub) tse4 = orth.chebyt(4)(psub) tse5 = orth.chebyt(5)(psub) assert_array_almost_equal(Ts0.c,tse0.c,13) assert_array_almost_equal(Ts1.c,tse1.c,13) assert_array_almost_equal(Ts2.c,tse2.c,13) assert_array_almost_equal(Ts3.c,tse3.c,13) assert_array_almost_equal(Ts4.c,tse4.c,12) assert_array_almost_equal(Ts5.c,tse5.c,12)