def g(x): """ Integrates to 1000 over [0,10]. """ return 3*x**2 def h(x): """ Integrates to 1.e11 + 1.e9 + 1000 over [0,10]. """ return 11*x**10 + x**9 + 3*x**2 print 'Single order-10 CC & F1 quads for f=1, g=3*x**2, h(x)=10th degree:' print '(Exact results: 10 1000 101000001000)' cc10 = ClenshawCurtis(10, 0, 10) print cc10.quad(f), cc10.quad(g), cc10.quad(h) f10 = Fejer1(10, 0, 10) print f10.quad(f), f10.quad(g), f10.quad(h) print 'Composite quad for above cases:' print cq.quad(f), cq.quad(g), cq.quad(h) print def plm3(x): """ Power-law integrand; integral = -1/x**2 """ return 2 * x**(-3.) def plm2(x): """ Power-law integrand; integral = -1/x.
Rolling exponential, -.6 at 1, -.4 at 10 """ return exp((alpha + .2*(x-.5*range)/range)*x) def rexp_map(y, alpha=alpha, range=range): """ Rolling exponential, transformed. """ x = x_y(y) return exp((alpha + .2*(x-.5*range)/range)*x) / exp(alpha*x) l, u = 1., range y_l, y_u = y_x(l), y_x(u) for n in [5, 10, 15, 25, 50, 100, 200, 500]: ccx = ClenshawCurtis(n, l, u) ccy = ClenshawCurtis(n, y_l, y_u) xq = ccx.quad(rexp) yq = ccy.quad(rexp_map) print n, xq, yq semilogy(ccx.nodes, rexp(ccx.nodes), 'b.') xlabel('$x$') ylabel('$f(x)$') figure() semilogy(ccy.nodes, rexp_map(ccy.nodes), 'g.') cc = ClenshawCurtis(25, y_l, y_u) semilogy(cc.nodes, rexp_map(cc.nodes), 'r.') xlabel('$y$') ylabel(r'$f(x)/\exp(\alpha x)$') show()
def g(x): """ Integrates to 1000 over [0,10]. """ return 3 * x**2 def h(x): """ Integrates to 1.e11 + 1.e9 + 1000 over [0,10]. """ return 11 * x**10 + x**9 + 3 * x**2 print 'Single order-10 CC & F1 quads for f=1, g=3*x**2, h(x)=10th degree:' print '(Exact results: 10 1000 101000001000)' cc10 = ClenshawCurtis(10, 0, 10) print cc10.quad(f), cc10.quad(g), cc10.quad(h) f10 = Fejer1(10, 0, 10) print f10.quad(f), f10.quad(g), f10.quad(h) print 'Composite quad for above cases:' print cq.quad(f), cq.quad(g), cq.quad(h) print def plm3(x): """ Power-law integrand; integral = -1/x**2 """ return 2 * x**(-3.) def plm2(x): """ Power-law integrand; integral = -1/x.
pl1 = -beta + .5 return (x/mid)**pl1 / (1. + x/mid) def roll_map(y, beta=beta, range=range, mid=mid): """ Rolling exponential, transformed. """ x = x_y(y) return roll(x) * x**beta l, u = 1., range y_l, y_u = y_x(l), y_x(u) for n in [5, 10, 15, 25, 50, 100, 200, 500]: ccx = ClenshawCurtis(n, l, u) ccy = ClenshawCurtis(n, y_l, y_u) xq = ccx.quad(roll) yq = ccy.quad(roll_map) print n, xq, yq loglog(ccx.nodes, roll(ccx.nodes), 'b.') cc = ClenshawCurtis(25, l, u) loglog(cc.nodes, roll(cc.nodes), 'r.') xlabel('$x$') ylabel('$f(x)$') figure() loglog(-ccy.nodes, roll_map(ccy.nodes), 'g.') cc = ClenshawCurtis(25, y_l, y_u) loglog(-cc.nodes, roll_map(cc.nodes), 'r.') xlabel('$-y$') ylabel(r'$f(x)/x^{-\beta}$') show()
def roll_map(y, beta=beta, range=range, mid=mid): """ Rolling exponential, transformed. """ x = x_y(y) return roll(x) * x**beta l, u = 1., range y_l, y_u = y_x(l), y_x(u) for n in [5, 10, 15, 25, 50, 100, 200, 500]: ccx = ClenshawCurtis(n, l, u) ccy = ClenshawCurtis(n, y_l, y_u) xq = ccx.quad(roll) yq = ccy.quad(roll_map) print n, xq, yq loglog(ccx.nodes, roll(ccx.nodes), 'b.') cc = ClenshawCurtis(25, l, u) loglog(cc.nodes, roll(cc.nodes), 'r.') xlabel('$x$') ylabel('$f(x)$') figure() loglog(-ccy.nodes, roll_map(ccy.nodes), 'g.') cc = ClenshawCurtis(25, y_l, y_u) loglog(-cc.nodes, roll_map(cc.nodes), 'r.') xlabel('$-y$') ylabel(r'$f(x)/x^{-\beta}$') show()