18 - Quadrature of data Adaptive quadrature Numerical...

This preview shows page 1 - 7 out of 20 pages.

Quadrature of data Adaptive quadrature Numerical Integration of Functions Dhavide Aruliah UOIT MATH 2070U c D. Aruliah (UOIT) Numerical Integration of Functions MATH 2070U 1 / 24
Quadrature of data Adaptive quadrature Numerical Integration of Functions 1 Numerical integration (quadrature) of numerical data sum and cumsum trapz and cumtrapz 2 Numerical integration of functions: adaptive quadrature Adaptive Simpson’s quadrature quad in M ATLAB Extensions of quad in M ATLAB c D. Aruliah (UOIT) Numerical Integration of Functions MATH 2070U 2 / 24
Quadrature of data Adaptive quadrature Reminder: Quadrature rules: Z b a f ( x ) dx n k = 0 w k f ( x k ) Rules derived from polynomial interpolation Common rules: trapezoidal rule, Simpson’s 1/3 rule Composite rules: break into smaller pieces c D. Aruliah (UOIT) Numerical Integration of Functions MATH 2070U 4 / 24
Quadrature of data Adaptive quadrature sum & cumsum sum and cumsum sum(y) returns sum of elements of y y = 1:7 S = sum(y) % returns a single scalar value cumsum(y) returns vector of cumulative sums (partial sums) of y y = 1:7 s = cumsum(y) % returns a *vector* For matrices/arrays, sum / cumsum operates on leading dimension Can be applied along other dimensions One-line command replacing traditional loop Similar functionality for prod and cumprod for arrays c D. Aruliah (UOIT) Numerical Integration of Functions MATH 2070U 5 / 24
Quadrature of data Adaptive quadrature trapz & cumtrapz Integrating discrete data Data prescribed from measurements { ( x k , y k ) } n k = 0 Trapezoidal rule (assume a = x 0 < x 1 · · · < x n = b ): Z b a f ( x ) dx 1 2 n k = 1 h k ( y k - 1 + y k ) with h k : = x k - x k - 1 ( k = 1: n ) M ATLAB “one-liner”: I_trap = 0.5*sum( diff(x) .* ( y(1:end-1)+y(2:end) ) Essential computation of M ATLAB routine trapz & cumtrapz Notice does not assume uniform spacing in x c D. Aruliah (UOIT) Numerical Integration of Functions MATH 2070U 6 / 24
Quadrature of data Adaptive quadrature trapz & cumtrapz Using trapz and cumtrapz Assume vectors x , y with y k = f ( x k ) ( k = 0: N ) trapz(x,y) Z x N x 0 f ( t ) dt : returns a single number x = (0:10)’; y = [0,1,4,9,16,25,36,49,64,81,100]’; I_approx = trapz (x,y) For k = 0: N , cumtrapz(x,y) k Z x k x 0 f ( t ) dt : returns a vector (samples of a function) x = (0:10)’; y = [0,1,4,9,16,25,36,49,64,81,100]’; I_approx = cumtrapz (x,y) c D. Aruliah (UOIT) Numerical Integration of Functions MATH 2070U 7 / 24

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture