Logo

QUADOSC

Updated 2024-03-07 15:15:12.867000

Syntax

SELECT [westlintech].[wct].[QUADOSC](
  <@Func, nvarchar(max),>
 ,<@VarName, nvarchar(4000),>
 ,<@A, sql_variant,>
 ,<@B, sql_variant,>
 ,<@Omega, float,>)

Description

Use the scalar function QUADOSC to evaluate an infinite integral. QUADOSC calculates the integral of the given function f(x) over the interval (-Infinity, Infinity) using Double Exponential Quadrature for 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 of a type which implicitly converts to nvarchar.

@Omega

the periodicity of the function. @Omega must be of the type float or of a type that implicitly converts to float.

@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.

If @Omega is NULL then @Omega is set to 1.

@Omega cannot be equal to zero.

@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 only periodic functions. For non-periodic functions use QUADDE instead.

Examples

In this example we want to evaluate the integral:

\int_0^\infty\frac{\sin{x}-x\cos{x}}{x^2}
SELECT wct.QUADOSC(   'SELECT (SIN(@x)-@x*COS(@x))/POWER(@x,2)', --@Func

                      '@x',                                      --@VarName

                      0,                                         --@A

                      'Inf',                                     --@B

                      1                                          --@Omega

                  ) as Integral;

This produces the following result.

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

In this example we want to evaluate the integral:

\int_{-\infty}^0\frac{\sin{x}-x\cos{x}}{x^2}
SELECT wct.QUADOSC(   'SELECT (SIN(@x)-@x*COS(@x))/POWER(@x,2)', --@Func

                      '@x',                                      --@VarName

                      '-Inf',                                    --@A

                      0,                                         --@B

                      1                                          --@Omega

                  ) as Integral;

This produces the following result.

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

In this example we want to evaluate the integral:

\int_{-\infty}^{\infty}e^{-16x^2}\cos{3(x+5)}
SELECT wct.QUADOSC(   'SELECT EXP(-16*POWER(@x,2))*COS(3*(@x+5))', --@Func

                      '@x',                                        --@VarName

                      '-Inf',                                      --@A

                      'Inf',                                       --@B

                      NULL                                         --@Omega

                  ) as Integral;

This produces the following result.

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

See Also

QUAD - Gauss-Kronrod 15-point quadrature

QUADDE - Double Exponential quadrature for non-periodic functions

QUADGK - Gauss-Kronrod 21-point quadrature

QUADTS - Evaluate a finite integral.