Logo

QUADDE

Updated 2024-03-07 14:50:27.907000

Syntax

SELECT [westclintech].[wct].[QUADDE](
  <@Func, nvarchar(max),>
 ,<@VarName, nvarchar(4000),>
 ,<@A, sql_variant,>
 ,<@B, sql_variant,>)

Description

Use the scalar function QUADDE to evaluate an infinite integral. QUADDE calculates the integral of the given function f(x) over the interval (-Infinity, Infinity) using Double Exponential Quadrature for non-Periodic functions.

Arguments

@A

the lower limit of integration.

@B

the upper limit of integration.

@VarName

the TSQL variable name. The variable name must start with '@'. @VarName must be of a type nvarchar or a type which implicitly converts to nvarchar.

@Func

the function to be integrated. @Func is a string containing any valid TSQL statement which includes a single variable that is the object of the integration. The variable name is defined in @VarName. @Func is of a type nvarchar or of any type which implicitly converts to nvarchar.

Return Type

float

Remarks

If @A is not '-Inf' and @B is not 'Inf' then NULL will be returned.

If @A is '-Inf' then the function will be integrate from -8 to @B.

If @A is not '-Inf' then the function will be integrated from @A to 8.

@A can be any floating point number or '-Inf'.

@B can be any floating point number or 'Inf'.

If @Func contains an undeclared SQL variable and it is not defined in @VarName a NULL will be returned.

For best results you should use only non-periodic functions. For periodic functions use QUADOSC instead.

Examples

In this example we want to evaluate the integral:

\int_1^\infty\frac{e^{-x}}{\sqrt{x}}
SELECT wct.QUADDE(   'SELECT EXP(-@x)/SQRT(@x)', --@Func    

                     '@x',                       --@VarName

                     0,                          --@A

                     'Inf'                       --@B

                 ) as Integral;

This produces the following result.

{"columns":[{"field":"Integral","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Integral":"1.77245385090552"}]}

In this example we want to evaluate the integral:

\int_{-\infty}^0\frac{1}{1+x^2}
SELECT wct.QUADDE(   'SELECT 1/(1+POWER(@x,2))', --@Func    

                     '@x',                       --@VarName

                     '-Inf',                     --@A

                     0                           --@B

                 ) as Integral;

This produces the following result.

{"columns":[{"field":"Integral","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Integral":"1.5707963267949"}]}

In this example we want to evaluate the integral:

\int_{-\infty}^\infty\frac{x^2}{1+4x+3x^2-4x^3-2x^4+2x^5+x^6}
SELECT wct.QUADDE(
                     'SELECT POWER(@x,2)/(1+4*@x+3*POWER(@x,2)-4*POWER(@x,3)-2*POWER(@x,4)+2*POWER(@x,5)+POWER(@x,6))', --@Func    
                     '@x',                                                                                              --@VarName
                     '-Inf',                                                                                            --@A
                     'Inf'                                                                                              --@B
                 ) as Integral;

This produces the following result.

{"columns":[{"field":"Integral","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Integral":"3.14159265358979"}]}

See Also

QUAD - Gauss-Kronrod 15-point quadrature

QUADGK - Gauss-Kronrod 21-point quadrature

QUADOSC - Double exponential quadrature for periodic functions

QUADTS - Evaluate a finite integral.