intFcnFourier

../../_images/OpenMP.png

Computes a Fourier sine or cosine transform.

Synopsis

intFcnFourier (fcn, a, weight, omega)

Required Arguments

float fcn (float x) (Input)
User-supplied function to be integrated.
float a (Input)
Lower limit of integration. The upper limit of integration is ∞.
int weight and float omega (Input)
These two parameters are used to describe the trigonometric weight. The parameter weight can take on the two values described below, and the parameter omega = ω specifies the frequency of the trigonometric weighting function.
weight Integration Weight
COS cos (ωx)
SIN sin (ωx)

Return Value

The return value is

\[\int_a^{\infty} \mathit{fcn}(x) \cos(\omega x) dx\]

if weight = COS. If weight = SIN, then the cosine factor is replaced with a sine factor. If no value can be computed, NaN is returned.

Optional Arguments

errAbs, float (Input)

Absolute accuracy desired.

Default: \(\mathit{errAbs} = \sqrt{\varepsilon}\) where ɛ is the machine precision

errEst, float (Output)
An estimate of the absolute value of the error.
maxSubinter, int (Input)

Number of subintervals allowed.

Default: maxSubinter = 500

maxCycles, int (Input)

Number of cycles allowed.

Default: maxCycles = 50

maxMoments, int (Input)

Number of subintervals allowed in the partition of each cycle.

Default: maxMoments = 21

nCycles (Output)
The number of cycles generated.
nEvals (Output)
The number of evaluations of fcn.

Description

The function intFcnFourier is a special-purpose integrator that uses a globally adaptive scheme to reduce the absolute error. It computes integrals whose integrands have the special form w(x)f(x) where w(x) is either cosωx or sinωx. The integration interval is always semi-infinite of the form [a, ∞]. These Fourier integrals are approximated by repeated calls to the function intFcnTrig followed by extrapolation.

The function intFcnFourier is based on the subroutine QAWF by Piessens et al. (1983).

Examples

Example 1

The value of

\[\int_{0}^{\infty} x^{-1/2} \cos(\pi x/2) dx = 1\]

is computed. Notice that the integrand is coded to protect for the singularity at zero.

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.intFcnFourier import intFcnFourier, COS


def fcn(x):
    if(x == 0):
        res = 0.0
    else:
        res = 1. / sqrt(x)
    return res


# Evaluate the integral
omega = constant("pi") / 2.0
q = intFcnFourier(fcn, 0.0, COS, omega)

# Print the result and the exact answer
exact = 1.
print("integral  = %10.3f\nexact     = %10.3f" % (q, exact))

Output

integral  =      1.000
exact     =      1.000

Example 2

The value of

\[\int_{0}^{\infty} x^{-1/2} \cos(\pi x/2) dx = 1\]

is again computed. The values of the actual and estimated error are printed as well. Note that these numbers are machine dependent. Furthermore, the error estimate is usually pessimistic. That is, the actual error is usually smaller than the error estimate, as is the case in this example.The number of function evaluations also are printed. Notice that the integrand is coded to protect for the singularity at zero.

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.intFcnFourier import intFcnFourier, COS


def fcn(x):
    if(x == 0):
        res = 0.0
    else:
        res = 1. / sqrt(x)
    return res


# Evaluate the integral
omega = constant("pi") / 2.0
err_est = []
n_evals = []
q = intFcnFourier(fcn, 0.0, COS, omega,
                  errEst=err_est,
                  nEvals=n_evals)

# Print the result and the exact answer
exact = 1.
exact_err = fabs(exact - q)
print("integral  = %10.3f\nexact     = %10.3f" % (q, exact))
print("error estimate   = %e\nexact error      = %e" %
      (err_est[0], exact_err))
print("The number of function evaluations  =  %d" % n_evals[0])

Output

integral  =      1.000
exact     =      1.000
error estimate   = 2.954510e-09
exact error      = 1.104583e-11
The number of function evaluations  =  615

Warning Errors

IMSL_BAD_INTEGRAND_BEHAVIOR Bad integrand behavior occurred in one or more cycles.
IMSL_EXTRAPOLATION_PROBLEMS Extrapolation table constructed for convergence acceleration of the series formed by the integral contributions of the cycles does not converge to the requested accuracy.

Fatal Errors

IMSL_MAX_CYCLES Maximum number of cycles allowed has been reached.
IMSL_STOP_USER_FCN

Request from user supplied function to stop algorithm.

User flag = “#”.