def check_gl_quad_chunks_extra_dims2(n): """check that gl_quad integrates polynomial of degree 3*n+1 (even) and 3*n+2 (odd)exactly, with multiple intervals with function that returns extra dims. This test is not rigorous because the polynomials formed can be fairly well approximated using lower order schemes """ #a, b = (-0.9, 1.3) a = np.array([-0.9, -0.4, .5]) b = np.array([-0.4, 0.5, 1.3]) coeff = np.arange(1, 3 * n + 1 + (n % 2)) coeff[::2] = coeff[::2] * -1.0 f = np.poly1d(coeff) def g(x): out = f(x) * np.arange(1, 9) return out g_ = g #np.vectorize(g) F = f.integ() exact = np.sum(F(b) - F(a)) * np.arange(1, 9) assert_allclose(gl_quad(g_, a, b, n=n, sum_intervals=True), exact, rtol=1e-3, atol=0)
def check_gl_quad(n): """check that gl_quad integrates polynomial of degree 2*n-1 'exactly' This test is not rigorous because the ploynmials formed can be fairly well approximated using lower order schemes""" a, b = (-0.9, 1.3) coeff = np.arange(1, 2*n+1) coeff[::2] =coeff[::2]*-1.0 f = np.poly1d(coeff) F = f.integ() exact = F(b) - F(a) assert_allclose(gl_quad(f,a,b, n=n), exact, rtol=1e-14,atol=0)
def check_gl_quad(n): """check that gl_quad integrates polynomial of degree 2*n-1 'exactly' This test is not rigorous because the polynomials formed can be fairly well approximated using lower order schemes""" a, b = (-0.9, 1.3) coeff = np.arange(1, 2 * n + 1) coeff[::2] = coeff[::2] * -1.0 f = np.poly1d(coeff) F = f.integ() exact = F(b) - F(a) assert_allclose(gl_quad(f, a, b, n=n), exact, rtol=1e-14, atol=0)
def check_gl_quad_chunks(n): """check that gk_quad integrates polynomial of degree 3*n+1 (even) and 3*n+2 (odd)exactly, with multiple intervals This test is not rigorous because the polynomials formed can be fairly well approximated using lower order schemes """ #a, b = (-0.9, 1.3) a = np.array([-0.9, -0.4, .5]) b = np.array([-0.4, 0.5, 1.3]) coeff = np.arange(1, 3*n + 1 + (n%2)) coeff[::2] =coeff[::2]*-1.0 f = np.poly1d(coeff) F = f.integ() exact = np.sum(F(b) - F(a)) assert_allclose(gl_quad(f,a,b, n=n, sum_intervals=True), exact, rtol=1e-3,atol=0)
def check_gl_quad_chunks(n): """check that gk_quad integrates polynomial of degree 3*n+1 (even) and 3*n+2 (odd)exactly, with multiple intervals This test is not rigorous because the polynomials formed can be fairly well approximated using lower order schemes """ #a, b = (-0.9, 1.3) a = np.array([-0.9, -0.4, .5]) b = np.array([-0.4, 0.5, 1.3]) coeff = np.arange(1, 3 * n + 1 + (n % 2)) coeff[::2] = coeff[::2] * -1.0 f = np.poly1d(coeff) F = f.integ() exact = np.sum(F(b) - F(a)) assert_allclose(gl_quad(f, a, b, n=n, sum_intervals=True), exact, rtol=1e-3, atol=0)
def check_gl_quad_chunks_extra_dims2(n): """check that gl_quad integrates polynomial of degree 3*n+1 (even) and 3*n+2 (odd)exactly, with multiple intervals with function that returns extra dims. This test is not rigorous because the polynomials formed can be fairly well approximated using lower order schemes """ #a, b = (-0.9, 1.3) a = np.array([-0.9, -0.4, .5]) b = np.array([-0.4, 0.5, 1.3]) coeff = np.arange(1, 3*n + 1 + (n%2)) coeff[::2] =coeff[::2]*-1.0 f = np.poly1d(coeff) def g(x): out = f(x)*np.arange(1,9) return out g_ = g#np.vectorize(g) F = f.integ() exact = np.sum(F(b) - F(a)) * np.arange(1,9) assert_allclose(gl_quad(g_,a,b, n=n, sum_intervals=True), exact, rtol=1e-3,atol=0)