Package quad provides numerical evaluation of definite integrals of single-variable functions.

    Evaluate the expected value of x^2 + 3 under a Weibull distribution
    EV with 10 points = 4.20175
    EV with 30 points = 4.19066
    EV with 100 points = 4.19064
    EV with 10000 points = 4.19064
    Estimate using parallel evaluations of f.
    EV = 4.19064




    This section is empty.


    This section is empty.


    func Fixed

    func Fixed(f func(float64) float64, min, max float64, n int, rule FixedLocationer, concurrent int) float64

      Fixed approximates the integral of the function f from min to max using a fixed n-point quadrature rule. During evaluation, f will be evaluated n times using the weights and locations specified by rule. That is, Fixed estimates

      int_min^max f(x) dx ≈ \sum_i w_i f(x_i)

      If rule is nil, an acceptable default is chosen, otherwise it is assumed that the properties of the integral match the assumptions of rule. For example, Legendre assumes that the integration bounds are finite. If rule is also a FixedLocationSingler, the quadrature points are computed individually rather than as a unit.

      If concurrent <= 0, f is evaluated serially, while if concurrent > 0, f may be evaluated with at most concurrent simultaneous evaluations.

      min must be less than or equal to max, and n must be positive, otherwise Fixed will panic.


      type FixedLocationSingler

      type FixedLocationSingler interface {
      	FixedLocationSingle(n, k int, min, max float64) (x, weight float64)

        FixedLocationSingle returns the location and weight for element k in a fixed quadrature rule with n total samples and integral bounds from min to max.

        type FixedLocationer

        type FixedLocationer interface {
        	FixedLocations(x, weight []float64, min, max float64)

          FixedLocationer computes a set of quadrature locations and weights and stores them in-place into x and weight respectively. The number of points generated is equal to the len(x). The weights and locations should be chosen such that

          int_min^max f(x) dx ≈ \sum_i w_i f(x_i)

          type Hermite

          type Hermite struct{}

            Hermite generates sample locations and weights for performing quadrature with a squared-exponential weight

            int_-inf^inf e^(-x^2) f(x) dx .

            func (Hermite) FixedLocations

            func (h Hermite) FixedLocations(x, weight []float64, min, max float64)

            type Legendre

            type Legendre struct{}

              Legendre integrates an unweighted function over finite bounds

              int_min^max f(x) dx

              func (Legendre) FixedLocationSingle

              func (l Legendre) FixedLocationSingle(n, k int, min, max float64) (x, weight float64)

              func (Legendre) FixedLocations

              func (l Legendre) FixedLocations(x, weight []float64, min, max float64)