nag 1d quad gauss (d01bac)

Similar documents
nag 1d quad gauss 1 (d01tac)

NAG Library Routine Document D01BAF.1

NAG Library Function Document nag_quad_md_gauss (d01fbc)

D01ARF NAG Fortran Library Routine Document

nag opt one var no deriv (e04abc)

NAG Library Function Document nag_1d_quad_inf_1 (d01smc)

SYDE 312 UNIT 4: EXTRA QUADRATURE PROBLEMS

NAG Library Function Document nag_quad_2d_fin (d01dac)

nag simple linear regression (g02cac)

Binary floating point encodings

nag tsa spectrum univar (g13cbc)

nag opt simplex (e04ccc)

NAG Library Routine Document D04AAF.1

nag tsa noise spectrum bivar (g13cgc)

NAG Library Function Document nag_1d_quad_wt_alglog_1 (d01spc)

NAG Library Function Document nag_1d_quad_wt_alglog (d01apc)

nag 1d spline deriv (e02bcc)

nag mv orthomax (g03bac)

nag opt check 2nd deriv (e04hdc)

A MIXED QUADRATURE FORMULA USING RULES OF LOWER ORDER

nag tsa cross spectrum bivar (g13cec)

CS321 Introduction To Numerical Methods

NAG Library Function Document nag_exp_integral (s13aac)

2.1.1 Fixed-Point (or Integer) Arithmetic

nag sparse nsym sol (f11dec)

nag anova random (g04bbc)

PHYSICS 115/242 Homework 2, Solutions

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD

2 Computation with Floating-Point Numbers

2 Computation with Floating-Point Numbers

NAG Fortran Library Routine Document D01AJF.1

Numerical Methods with Matlab: Implementations and Applications. Gerald W. Recktenwald. Chapter 11 Numerical Integration

NAG C Library Function Document nag_binary_factor_service (g11sbc)

NAG Library Function Document nag_multid_quad_monte_carlo_1 (d01xbc)

NAG C Library Function Document nag_multid_quad_monte_carlo_1 (d01xbc)

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

NAG Library Function Document nag_durbin_watson_stat (g02fcc)

Scientific Computing. Error Analysis

nag regsn mult linear upd model (g02ddc)

Floating-point numbers. Phys 420/580 Lecture 6

PHYSICS 115/242 Homework 5, Solutions X = and the mean and variance of X are N times the mean and variance of 12/N y, so

NAG Library Function Document nag_zero_cont_func_brent_rcomm (c05azc)

Cubature Rules for High-dimensional Adaptive Integration

nag complex svd (f02xec)

nag 2d spline eval rect (e02dfc)

NAG C Library Function Document nag_superlu_condition_number_lu (f11mgc)

nag opt lsq no deriv (e04fcc)

(Type your answer in radians. Round to the nearest hundredth as needed.)

Catholic Central High School

nag regsn mult linear delete var (g02dfc)

Introduction to numerical algorithms

nag glm est func (g02gnc)

NAG Library Function Document nag_rgsn_matrix_multi_normal (g05lyc)

Wiswall, Applied Microeconometrics, Lecture Notes 1. In this section we focus on three very common computational tasks in applied

CS 450 Numerical Analysis. Chapter 7: Interpolation

NAG Library Function Document nag_prob_durbin_watson (g01epc)

Review Questions 26 CHAPTER 1. SCIENTIFIC COMPUTING

Truncation Errors. Applied Numerical Methods with MATLAB for Engineers and Scientists, 2nd ed., Steven C. Chapra, McGraw Hill, 2008, Ch. 4.

nag regsn mult linear add var (g02dec)

NAG Library Function Document nag_legendre_p (s22aac)

Numerical Integration

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

NAG Library Function Document nag_specfun_1f1_real (s22bac)

Floating-point representation

Numerical Aspects of Special Functions

1-3 Continuity, End Behavior, and Limits

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

nag regsn mult linear est func (g02dnc)

9.1 Bracketing and Bisection

Math 113 Exam 1 Practice

NAG Library Function Document nag_zero_nonlin_eqns_deriv_1 (c05ubc)

NAG Library Function Document nag_1d_spline_interpolant (e01bac)

Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming

Catholic Central High School

Most nonzero floating-point numbers are normalized. This means they can be expressed as. x = ±(1 + f) 2 e. 0 f < 1

NAG Library Function Document nag_ode_bvp_ps_lin_cheb_eval (d02uzc)

NAG C Library Function Document nag_kruskal_wallis_test (g08afc)

Unavoidable Errors in Computing

1.00 Lecture 32. Integration. Reading for next time: Numerical Recipes Packaging Functions in Objects

1 of 21 8/6/2018, 8:17 AM

Contents. Hilary Term. Summary of Numerical Analysis for this term. Sources of error in numerical calculation. Solving Problems

Power Series and Summation

NAG Fortran Library Routine Document G05LZF.1

correlated to the Michigan High School Mathematics Content Expectations

NAG Library Function Document nag_2_sample_ks_test (g08cdc)

nag mv kmeans cluster analysis (g03efc)

NAG Library Function Document nag_5d_shep_eval (e01tnc)

NAG Library Function Document nag_zeros_complex_poly (c02afc)

Loops / Repetition Statements

Santiago AP Calculus AB/BC Summer Assignment 2018 AB: complete problems 1 64, BC: complete problems 1 73

NUMERICAL INTEGRATION AND FUNCTION FUNCTIONS


MAT128A: Numerical Analysis Lecture One: Course Logistics and What is Numerical Analysis?

9.1 Bracketing and Bisection

Computational Mathematics: Models, Methods and Analysis. Zhilin Li

Chapter 1. Numeric Artifacts. 1.1 Introduction

Computer arithmetics: integers, binary floating-point, and decimal floating-point

1.00 Lecture 19. Numerical Methods: Root Finding

Functions. Edexcel GCE. Core Mathematics C3

NAG Library Function Document nag_2_sample_ks_test (g08cdc)

Transcription:

1. Purpose nag 1d quad gauss () nag 1d quad gauss () computes an estimate of the definite integral of a function of known analytical form, using a Gaussian quadrature formula with a specified number of abscissae. Formulae are provided for a finite interval (Gauss-Legendre), a semi-infinite interval (Gauss- Laguerre, Gauss-Rational), and an infinite interval (Gauss-Hermite). 2. Specification #include <nag.h> #include <nagd01.h> double nag_1d_quad_gauss(nag_gaussformulae quadrule, double (*f)(double x), double a, double b, Integer npts, NagError *fail) 3. Description 3.1. General This function evaluates an estimate of the definite integral of a function f(x), over a finite or infinite interval, by n-point Gaussian quadrature (see Davis and Rabinowitz (1967), Froberg (1965), Ralston (1965) or Stroud and Secrest (1966)). The integral is approximated by a summation n ω i f(x i ) i=1 where ω i are called the weights, and the x i the abscissae. A selection of values of n is available. (See Section 4.) 3.2. Both Limits Finite b a f(x) dx The Gauss-Legendre weights and abscissae are used, and the formula is exact for any function of the form: f(x) = 2n 1 c i x i The formula is appropriate for functions which can be well approximated by such a polynomial over [a, b]. It is inappropriate for functions with algebraic singularities at one or both ends of the 1 interval, such as on [ 1, 1]. (1+x) 3.3. One Limit Infinite a f(x) dx or a f(x) dx. Two quadrature formulae are available for these integrals. (a) The Gauss-Laguerre formula is exact for any function of the form: 2n 1 f(x) =e bx c i x i This formula is appropriate for functions decaying exponentially at infinity; the parameter b should be chosen if possible to match the decay rate of the function. 3..1

nag 1d quad gauss NAG C Library Manual (b) The Gauss-Rational formula is exact for any function of the form: f(x) = 2n+1 i=2 c i (x + b) i = 2n 1 c 2n+1 i (x + b) i (x + b) 2n+1 This formula is likely to be more accurate for functions having only an inverse power rate of decay for large x. Here the choice of a suitable value of b may be more difficult; unfortunately apoorchoiceofb can make a large difference to the accuracy of the computed integral. 3.4. Both Limits Infinite f(x) dx. The Gauss-Hermite weights and abscissae are used, and the formula is exact for any function of the form: 2n 1 f(x) =e b(x a)2 c i x i. Again, for general functions not of this exact form, the parameter b should be chosen to match if possible the decay rate at ±. 4. Parameters quadrule Members of this enum type indicate the quadrature formula: Nag Legendre, for Gauss-Legendre quadrature on a finite interval; Nag Rational, for Gauss-Rational quadrature on a semi-infinite interval; Nag Laguerre, for Gauss-Laguerre quadrature on a semi-infinite interval; Nag Hermite, for Gauss-Hermite quadrature on an infinite interval. f The function f, supplied by the user, must return the value of the integrand f at a given point. The specification of f is: double f(double x) x Input: the point at which the integrand f must be evaluated. a b Some points to bear in mind when coding f are mentioned in Section 6. Input: the parameters a and b which occur in the integration formulae: Gauss-Legendre: a is the lower limit and b is the upper limit of the integral. It is not necessary that a<b. Gauss-Rational: b must be chosen so as to make the integrand match as closely as possible the exact form given in Section 3.3(b). The interval of integration is [a, ) ifa + b>0, and (,a]if a + b<0. Gauss-Laguerre: b must be chosen so as to make the integrand match as closely as possible the exact form given in Section 3.3(a). The interval of integration is [a, ) ifb>0, and (,a]isb<0. Gauss-Hermite: a and b must be chosen so as to make the integrand match as closely as possible the exact formgiveninsection3.4. Constraints: Gauss-Rational: a+b 0 Gauss-Laguerre: b 0 Gauss-Hermite: b > 0. 3..2

npts fail Input: the number of abscissae to be used, n. Constraint: npts = 1,2,3,4,5,6,8,10,12,14,16,20,24,32,48 or 64. The NAG error parameter, see the Essential Introduction to the NAG C Library. Users are recommended to declare and initialise fail and set fail.print = TRUE for this function. 5. Error Indications and Warnings NE BAD PARAM On entry, parameter quadrule had an illegal value. NE QUAD GAUSS NPTS RULE The N-point rule is not among those stored. The answer is evaluated for value, the largest possible value of npts less than the requested value, value. NE QUAD GAUSS CONS Gauss-Rational input is invalid with a + b =0. Constraint: a + b 0. Gauss-Laguerre input is invalid with b = 0. Constraint: b 0. Gauss-Hermite input is invalid with b 0. Constraint: b > 0. The answer is returned as zero. 6. Further Comments The time taken by the routine depends on the complexity of the expression for the integrand and on the number of abscissae required. 6.1. Accuracy The accuracy depends on the behaviour of the integrand, and on the number of abscissae used. No tests are carried out in the routine to estimate the accuracy of the result. If such an estimate is required, the routine may be called more than once, with a different number of abscissae each time, and the answers compared. It is to be expected that for sufficiently smooth functions a larger number of abscissae will give improved accuracy. Alternatively, the interval of integration may be subdivided, the integral estimated separately for each sub-interval, and the sum of these estimates compared with the estimate over the whole interval. The coding of the function f may also have a bearing on the accuracy. For example, if a high-order Gauss-Laguerre formula is used, and the integrand is of the form f(x) =e bx g(x) it is possible that the exponential term may underflow for some large abscissae. Depending on the machine, this may produce an error, or simply be assumed to be zero. In any case, it would be better to evaluate the expression as: f(x) =exp( bx +lng(x)). Another situation requiring care is exemplified by e x2 x m dx =0, m odd. The integrand here assumes very large values; for example, for m = 63, the peak value exceeds 3 10 33. Now, if the machine holds floating-point numbers to an accuracy of k significant decimal 3..3

nag 1d quad gauss NAG C Library Manual digits, we could not expect such terms to cancel in the summation leaving an answer of much less than 10 33 k (the weights being of order unity); that is instead of zero, we obtain a rather large answer through rounding error. Fortunately, such situations are characterised by great variability in the answers returned by formulae with different values of n. In general, the user should be aware of the order of magnitude of the integrand, and should judge the answer in that light. 6.2. References Davis P J and Rabinowitz P (1967) Numerical Integration Blaisdell Publishing Company pp. 33 52. Froberg C E (1965) Introduction to Numerical Analysis Addison-Wesley pp. 181 187. Ralston A (1965) A First Course in Numerical Analysis McGraw-Hill pp. 87 90. Stroud A H and Secrest D (1966) Gaussian Quadrature Formulas Prentice-Hall. 7. See Also None. 8. Example This example program evaluates the integrals 1 4 0 1+x 2 dx = π by Gauss-Legendre quadrature; 1 2 x 2 dx =0.378671 ln x by Gauss-Rational quadrature with b =0; e x dx =0.048901 2 x by Gauss-Laguerre quadrature with b =1;and e 3x2 4x 1 dx = e 3(x+1)2 e 2x+2 dx =1.428167 by Gauss-Hermite quadrature with a = 1 andb =3. The formulae with n =4, 8, 16 are used in each case. 8.1. Program Text /* nag_1d_quad_gauss() Example Program * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. */ #include <nag.h> #include <stdio.h> #include <nag_stdlib.h> #include <math.h> #include <nagd01.h> static double fun1(double x); static double fun1(); static double fun2(double x); static double fun2(); 3..4

static double fun3(double x); static double fun3(); static double fun4(double x); static double fun4(); main() static Integer nstor[3] = 4, 8, 16; double a, b; Integer i; static NagError fail; double ans; Nag_GaussFormulae gaussformula; Boolean success = TRUE; fail.print = TRUE; Vprintf(" Example Program Results\n"); Vprintf("\nGauss-Legendre example\n\n"); for (; i<3; ++i) a = 0.0; b = 1.0; gaussformula = Nag_Legendre; ans = (gaussformula, fun1, a, b, nstor[i], &fail); Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); Vprintf("\nGauss-Rational example\n\n"); for (; i<3; ++i) a = 2.0; b = 0.0; gaussformula = Nag_Rational; ans = (gaussformula, fun2, a, b, nstor[i], &fail); Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); Vprintf("\nGauss-Laguerre example\n\n"); for (; i<3; ++i) a = 2.0; b = 1.0; gaussformula = Nag_Laguerre; ans = (gaussformula, fun3, a, b, nstor[i], &fail); Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); 3..5

nag 1d quad gauss NAG C Library Manual Vprintf("\nGauss-Hermite example\n\n"); for (; i<3; ++i) a = -1.0; b = 3.0; gaussformula = Nag_Hermite; ans = (gaussformula, fun4, a, b, nstor[i], &fail); Vprintf("%ld Points Answer = %10.5f\n\n", nstor[i], ans); if (success) exit(exit_success); exit(exit_failure); /* main */ static double fun1(double x) static double fun1(x) return 4.0/(x*x+1.0); static double fun2(double x) static double fun2(x) return 1.0/(x*x*log(x)); static double fun3(double x) static double fun3(x) return exp(-x)/x; static double fun4(double x) static double fun4(x) return exp(x*(-3.0)*x-x*4.0-1.0); 8.2. Program Data None. 3..6

8.3. Program Results Example Program Results Gauss-Legendre example 4 Points Answer = 3.14161 8 Points Answer = 3.14159 16 Points Answer = 3.14159 Gauss-Rational example 4 Points Answer = 0.37910 8 Points Answer = 0.37876 16 Points Answer = 0.37869 Gauss-Laguerre example 4 Points Answer = 0.04887 8 Points Answer = 0.04890 16 Points Answer = 0.04890 Gauss-Hermite example 4 Points Answer = 1.42803 8 Points Answer = 1.42817 16 Points Answer = 1.42817 3..7