Logo

QUADTS

Updated 2024-03-07 15:31:00.310000

Syntax

SELECT [wctMath].[wct].[QUADTS](
  <@Func, nvarchar(max),>
 ,<@VarName, nvarchar(4000),>
 ,<@A, float,>
 ,<@B, float,>)

Description

Use the scalar function QUADTS to evaluate a finite integral. QUADTS calculates the integral of the given function f(x) over the interval (a,b) using the Tanh-Sinh method.

Arguments

@A

The lower limit of integration. @A must be of a type float or of a type that implicitly converts to float.

@B

The upper limit of integration. @B must be of a type float or of a type that implicitly converts to float.

@VarName

the TSQL variable name. The variable name must start with '@'. @VarName must be of a type nvarchar or of 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 not less than @B an error will be returned.

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

Examples

In this example we want to evaluate the integral:

\int_0^1\frac{1}{x^3+1}
SELECT wct.QUADTS(   'SELECT 1/(POWER(@x,3) + 1)', --@Func    

                     '@x',                         --@VarName

                     0,                            --@A

                     1                             --@B

                 ) as Integral;

This produces the following result.

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

In this example we want to evaluate the integral:

\int_0^5\lceil{x^2}+\lfloor{x}\rfloor\rceil
SELECT wct.QUADTS(   'SELECT CEILING(POWER(@x,2)+FLOOR(@x))', --@Func    

                     '@x',                                    --@VarName

                     0,                                       --@A

                     5                                        --@B

                 ) as Integral;

This produces the following result.

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

In this example we want to evaluate the integral:

\int_{-2}^2\frac{\pi}{2}\cosh{x}\sin{e^{\frac{\pi}{2}\sinh{x}}}

Note that COSH , the hyperbolic cosine function, and SINH , the hyperbolic sine function, are not a built-in SQL Server functions but are part of the XLeratorDB library.

SELECT wct.QUADTS(   'SELECT PI()/2e+00*wct.COSH(@x)*SIN(EXP(PI()/2e+00*wct.SINH(@x)))', --@Func
                     '@x',                                                               --@VarName
                     -2,                                                                 --@A
                     2                                                                   --@B
                 ) as Integral;

This produces the following result.

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

In this example we want to evaluate the integral:

\int_0^1\ln\left(\frac{1+\sqrt{1+4x}}{2}\right)\slash{x}
SELECT
   wct.QUADTS(
      'SELECT LOG((1+SQRT(1+4*@x))/2)/@x',      --@Func    
      '@x',             --@VarName
      0,                --@A
      1                 --@B
      ) as Integral;

This produces the following result.

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

See Also

QUAD - Gauss-Kronrod 15-point quadrature

QUADDE - Double Exponential quadrature for non-periodic functions

QUADGK - Gauss-Kronrod 21-point quadrature

QUADOSC - Double exponential quadrature for periodic functions