Contenu principal

integralInterpolant

R2026b

Definite integral interpolation

Since R2026b

    Description

    Use integralInterpolant to evaluate a definite integral with a variable upper limit.

    integralInterpolant returns an object that interpolates the partial sum of an approximation of ∫abf(t)dt and is used to evaluate F(x)=∫axf(t)dt for values of x between a and b. You can evaluate the interpolant F at a set of values, such as [x1 x2 x3], to calculate the interpolated values, [F(x1) F(x2) F(x3)].

    Creation

    Description

    F = integralInterpolant(integrand,lower,upper) creates an integralInterpolant object that interpolates the integral of the function integrand with limits lower to upper.

    example

    F = integralInterpolant(integrand,lower,upper,Name=Value) specifies options using one or more name-value arguments. For example, specify Waypoints as a vector of real numbers to indicate specific points for the integrator to use.

    example

    Input Arguments

    expand all

    Integrand, specified as a function handle that defines the function to be integrated.

    This argument sets the Integrand property.

    Lower limit of the integral, specified as a real (finite or infinite) number. The lower limit corresponds to the limit a in the integral ∫abf(t)dt. The upper limit can be less than the lower limit because integralInterpolant supports backward integration, but the upper limit and lower limit cannot be equal.

    This argument sets the LowerLimit property.

    Data Types: double | single

    Upper limit of the integral, specified as a real (finite or infinite) number. The upper limit corresponds to the limit b in the integral ∫abf(t)dt. The upper limit can be less than the lower limit because integralInterpolant supports backward integration, but the upper limit and lower limit cannot be equal.

    This argument sets the UpperLimit property.

    Data Types: double | single

    Name-Value Arguments

    expand all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: F = integralInterpolant(integrand,lower,upper,AbsoluteTolerance=1e-12) sets the absolute error tolerance to approximately 12 decimal places of accuracy.

    Absolute error tolerance, specified as a nonnegative real number. integralInterpolant uses the absolute error tolerance to limit an estimate of the absolute error, |q – Q|, where q is the computed value of the integral and Q is the (unknown) exact value. integralInterpolant might provide more decimal places of precision if you decrease the absolute error tolerance.

    Note

    AbsoluteTolerance and RelativeTolerance work together. integralInterpolant might satisfy the absolute error tolerance or the relative error tolerance, but not necessarily both. For more information on using these tolerances, see the Tips section.

    Data Types: double | single

    Relative error tolerance, specified as a nonnegative real number. integralInterpolant uses the relative error tolerance to limit an estimate of the relative error, |q – Q|/|Q|, where q is the computed value of the integral and Q is the (unknown) exact value. integralInterpolant might provide more significant digits of precision if you decrease the relative error tolerance.

    Note

    RelativeTolerance and AbsoluteTolerance work together. integralInterpolant might satisfy the relative error tolerance or the absolute error tolerance, but not necessarily both. For more information on using these tolerances, see the Tips section.

    Data Types: double | single

    Function is array-valued, specified as a numeric or logical 1 (true) or 0 (false). Specify ArrayValued as true or 1 to indicate that integrand is a function that accepts a scalar input and returns a vector, matrix, or N-D array output.

    The default value of false indicates that the integrand function accepts a vector input and returns a vector output.

    Perform vectorized computation, specified as a numeric or logical 1 (true) or 0 (false). By default, Vectorized is true and the computation of the integral is vectorized to run faster. For scalar-valued functions, the integrand function y = integrand(x) must accept a vector argument x and operate element-wise, returning a vector result y.

    If you specify Vectorized as false, then the integrand function accepts only a scalar argument x and returns a scalar result y.

    Note

    If you specify ArrayValued as true, then integralInterpolant ignores the value of Vectorized.

    Integration waypoints, specified as a vector of real numbers. Use waypoints to indicate points in the integration interval that you want the integrator to use in the initial mesh:

    • Add more evaluation points near interesting features of the function, such as a local extremum. When there is a singularity at the upper or lower limit of integration, inserting waypoints near it may improve the accuracy of the interpolant there.

    • Integrate efficiently across discontinuities of the integrand by specifying the locations of the discontinuities.

    Do not use waypoints to specify singularities. Instead, split the interval and add the results of separate integrations with the singularities at the endpoints.

    Data Types: double | single

    Output Arguments

    expand all

    Definite integral interpolant, returned as an integralInterpolant object. You can evaluate F to calculate the interpolated integral values at a set of points.

    Properties

    expand all

    This property is read-only.

    Integrand, represented as a function handle that defines the function to be integrated.

    This property is read-only.

    Lower limit of the integral, represented as a real (finite or infinite) number. The lower limit corresponds to the limit a in the integral ∫abf(t)dt.

    Data Types: double | single

    This property is read-only.

    Upper limit of the integral, represented as a real (finite or infinite) number. The upper limit corresponds to the limit b in the integral ∫abf(t)dt.

    Data Types: double | single

    This property is read-only.

    Integral, represented as a real number, complex number, or array of real or complex numbers.

    Data Types: double | single

    This property is read-only.

    Approximate upper bound on absolute error, represented as a real number. The approximate upper bound on absolute error in the integration is |q – Q|, where q is the computed value of the integral and Q is the (unknown) exact value. integralInterpolant attempts to satisfy this condition:

    errbnd <= max(AbsTol,RelTol*abs(q))
    The error bound indicates how well the integration meets the AbsoluteTolerance and RelativeTolerance error tolerances.

    ErrorBound is the same size as Integral.

    Data Types: double | single

    This property is read-only.

    Subintervals used in integral calculation, represented as an array of real numbers. The subintervals include the integration waypoints specified in the Waypoints name-value argument.

    Data Types: double | single

    Examples

    collapse all

    Evaluate F(x)=∫0x1+cos2(t)dt for 0≤x≤5 by creating an integralInterpolant object.

    f = @(x) 1 + cos(x).^2;
    F = integralInterpolant(f,0,5)
    F = 
      integralInterpolant with properties:
    
                Integrand: @(x)1+cos(x).^2
               LowerLimit: 0
               UpperLimit: 5
                 Integral: 7.3640
               ErrorBound: 3.1171e-16
        AbsoluteTolerance: 1.0000e-10
        RelativeTolerance: 1.0000e-06
             Subintervals: [0 5.8350e-04 0.0023 0.0092 0.0362 0.1400 0.5200 1.0800 1.7600 2.5000 3.2400 3.9200 4.4800 4.8600 4.9638 4.9908 4.9977 4.9994 5]
    
    

    F(x) evaluated for 0≤x≤5 is 7.364. Query the interpolant at five uniformly spaced points between 1 and 3.

    xq = linspace(1,3,5);
    Fq = F(xq)
    Fq = 1×5
    
        1.7273    2.2853    2.8108    3.5103    4.4301
    
    

    Evaluate F(x)=∫0xt5e-tsin(t)dt for 0≤x<∞ by creating an integralInterpolant object. For higher accuracy interpolation, specify absolute and relative error tolerances that are stricter than the default tolerances.

    f = @(x) x.^5.*exp(-x).*sin(x);
    F = integralInterpolant(f,0,Inf,RelativeTolerance=1e-8,AbsoluteTolerance=1e-13)
    F = 
      integralInterpolant with properties:
    
                Integrand: @(x)x.^5.*exp(-x).*sin(x)
               LowerLimit: 0
               UpperLimit: Inf
                 Integral: -15.0000
               ErrorBound: 9.4386e-09
        AbsoluteTolerance: 1.0000e-13
        RelativeTolerance: 1.0000e-08
             Subintervals: [0 3.9555e-05 1.6023e-04 6.5746e-04 0.0028 0.0123 0.0625 0.1837 0.4444 1 2.2500 3.4490 5.4444 6.9504 9 11.8642 16.0000 22.2245 32.1111 81.0000 361.0000 1.5210e+03 6.2410e+03 2.5281e+04 Inf]
    
    

    F(x) evaluated for 0≤x<∞ is –15. Query the interpolant at the lower and upper limits of the integral.

    xq = [0 Inf];
    Fq = F(xq)
    Fq = 1×2
    
             0  -15.0000
    
    

    Evaluate F(x)=∫0xf(t)dt for 0≤x≤1, where f(t) is the vector-valued function f(t)=[sin(t),sin(2t),sin(3t),sin(4t),sin(5t)]. To evaluate the integral of an array-valued or vector-valued function, create an integralInterpolant object and specify the ArrayValued name-value argument as true.

    f = @(x) sin((1:5)*x);
    F = integralInterpolant(f,0,1,ArrayValued=true)
    F = 
      integralInterpolant with properties:
    
                Integrand: @(x)sin((1:5)*x)
               LowerLimit: 0
               UpperLimit: 1
                 Integral: [0.4597 0.7081 0.6633 0.4134 0.1433]
               ErrorBound: [2.1678e-17 5.8856e-18 4.0456e-18 4.6866e-18 6.8779e-19]
        AbsoluteTolerance: 1.0000e-10
        RelativeTolerance: 1.0000e-06
             Subintervals: [0 1.1670e-04 4.6484e-04 0.0018 0.0072 0.0280 0.1040 0.2160 0.3520 0.5000 0.6480 0.7840 0.8960 0.9720 0.9928 0.9982 0.9995 0.9999 1]
    
    

    Get a subset of the partial sums for each element of f(t) by querying the interpolant at the last five subintervals. Each column of partialSums corresponds to an element of f(t).

    partialSums = F(F.Subintervals(end-5:end))
    partialSums = 6×5
    
        0.4364    0.6823    0.6582    0.4335    0.1706
        0.4536    0.7015    0.6622    0.4188    0.1503
        0.4581    0.7064    0.6631    0.4148    0.1450
        0.4593    0.7077    0.6633    0.4138    0.1437
        0.4596    0.7080    0.6633    0.4135    0.1434
        0.4597    0.7081    0.6633    0.4134    0.1433
    
    

    integralInterpolant uses a high-order interpolation method. To evaluate an integral with a less accurate but faster interpolant method, you can convert an integralInterpolant object to a griddedInterpolant object.

    Create an integralInterpolant object to evaluate F(x)=∫1xttdt for 1≤x≤2.

    f = @(x) x.^x;
    F = integralInterpolant(f,1,2);

    Convert the integralInterpolant object to a griddedInterpolant object that uses the cubic interpolation method on an evenly spaced grid of 11 points.

    x = linspace(1,2,11);
    G = griddedInterpolant(x,F(x),"cubic");

    Compare the results by querying the two interpolants at a single point.

    xq = 1.88;
    Fq = F(xq)
    Fq = 
    1.6156
    
    Gq = G(xq)
    Gq = 
    1.6154
    

    Tips

    • The integralInterpolant object attempts to satisfy the following expression, where q is the computed value of the integral and Q is the (unknown) exact value.

      abs(q - Q) <= max(AbsoluteTolerance,RelativeTolerance*abs(q))
      The absolute and relative tolerances provide a way to balance accuracy and computation time. Usually, the relative tolerance determines the accuracy of the integration. However, if abs(q) is sufficiently small, the absolute tolerance determines the accuracy of the integration. As a best practice, specify both absolute and relative tolerances together.

    • If you specify single-precision limits of integration, or if the integrand returns single-precision results, you might need to specify larger absolute and relative error tolerances.

    • You can get the partial sums of the interpolated integral by passing the Subintervals property to the interpolant. For example, this code returns the partial sums of interpolant F, which approximates the definite integral from LowerLimit to UpperLimit:

      PartialSums = F(F.Subintervals)

    • integralInterpolant uses a high-order interpolation method. If you want faster performance but not necessarily better accuracy, you can convert your integralInterpolant object to a griddedInterpolant object.

    Version History

    Introduced in R2026b

    See Also

    Functions

    Objects