In this exercise you have to implement a subroutine which integrates a given function f(x) from a to b with the absolute accuracy goal δ and realtive accuracy goal ε. The subroutine should return the estimate of the integral, Q, with the error smaller than δ+ε|Q|.
Exercises
(6 points) Recursive adaptive integrator
Implement a recursive adaptive integrator that estimates the integral of a given function f(x) on a given interval [a,b] with the required absolute, δ, or relative, ε, accuracy goals.
The integrator has to use a combination of a higher order quadrature and an imbedded lower order quadrature (to estimate the local error).
Something like
double integrate(double f(double), double a, double b, double δ, double ε) { double Q = higher_order_rule, q = lower_order_rule, err=|Q-q|; if (err < δ+ε|Q|) return Q; else return integrate(f,a,(a+b)/2,δ/√2,ε)+ integrate(f,(a+b)/2,b,δ/√2,ε); }
Reuse points!
Test your implementation on some interesting integrals, for example (check the expressions before using),
∫01 dx √(x) = 2/3 , ∫01 dx 4√(1-x²) = π
(3 points) Open quadrature with Clenshaw–Curtis variable transformation
∫-11 f(x)dx = ∫0π f(cos(θ))sinθdθ
∫abdx f(x) = ∫0πdθ f( (a+b)/2+(b-a)/2*Cos(θ) )*Sin(θ)*(b-a)/2
∫01 dx 1/√(x) = 2 , ∫01 dx ln(x)/√(x) = -4 .
∫01 dx 4√(1-x²) = πwith as many significant digits as possible with and without Clenshaw-Curtis transformation. Compare the accuracy and the number of evaluations.
(1 point) Infinite limits
man INFINITY
,
man isinf
.