Approximating definite integrals

### 21.2.2 Approximating definite integrals

The romberg or nInt command finds approximate values of integrals using the Romberg method.

- romberg takes three mandatory arguments and one optional argument:
  - expr, an expression involving one variable.
  - Optionally, var, the variable (by default x).
  - a,b, two real numbers.
- romberg(expr ⟨,var,⟩ a,b) returns an approximated value of the integral ∫abexpr·dvar. The integrand must be sufficiently regular for the approximation to be accurate, otherwise, romberg returns a list of real values that come from the application of the Romberg algorithm (the first list element is the trapezoid rule approximation, the next ones come from the application of the Euler-Maclaurin formula to remove successive even powers of the step of the trapezoid rule).

The gaussquad command finds an approximate value of an integral, calculated by an adaptive method by Ernst Hairer which uses a 15-point Gaussian quadrature.

- gaussquad takes four arguments:
  - expr, an expression.
  - var, the variable used by the expression.
  - a,b, two numbers.
- gaussquad(expr,a,b) returns an approximation of the integral ∫abexpr·dvar.

#### Example

romberg(exp(x^2),x,0,1)

1.46265174591 |  |  |  |  |  |  |  |  |  |

gaussquad(exp(x^2),x,0,1)

1.46265174591 |  |  |  |  |  |  |  |  |  |

gaussquad(exp(-x^2),x,-1,1)

1.49364826562 |  |  |  |  |  |  |  |  |  |