Logo

BRENT

Updated 2023-10-18 20:31:16.563000

Syntax

SELECT [westclintech].[wct].[BRENT] (
   <@Func, nvarchar(max),>
  ,<@VarName, nvarchar(4000),>
  ,<@A, float,>
  ,<@B, float,>
  ,<@MaxIter, int,>
  ,<@tol, float,>)

Description

Use the scalar function BRENT to find the root of a continuous function of one variable.

Arguments

@tol

Absolute tolerance.

@A

One of the 2 starting values.

@B

Another starting value.

@VarName

The name of the variable.

@MaxIter

Maximum number of iterations.

@Func

The function to be evaluated, as a string. The function must be in the form of a SELECT statement.

Return Type

float

Remarks

If Func returns a NULL then NULL Is returned.

If Func is not a valid SELECT statement then NULL is returned.

If no solution is found then NULL is returned.

The solution must be bound by A and B.

If A is NULL then A = 0

If B is NULL then B = 0

If MaxIter is NULL then MaxIter = 100

If tol is NULL then tol = 0.

f tol <= 0 then tol = 0.0000000149011612.

Examples

Example #1

Let’s find the root of the Legendre polynomial of degree 5.

SELECT wct.BRENT('SELECT (63 * POWER(@x,5) - 70 * POWER(@x,3) + 15 * @x)/8e+00', 

          '@x', 0.9, 1.0, NULL, NULL) as brent;

This produces the following result.

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

Example #2

In this example we call the PRICE function to calculate the yield on a bond using the BRENT function and compare that with value returned by the YIELD function.

SELECT wct.BRENT(

                    'SELECT wct.PRICE(

             ''2018-04-25''

            ,''2025-05-15''

            ,.04

            ,@Y

            ,100

            ,2

            ,0) - 98.25',

                    '@Y',

                    .04,

                    .12,

                    NULL,

                    1E-08

                ) as brent,

       wct.YIELD('2018-04-25', '2025-05-15', .04, 98.25, 100, 2, 0) as yield;

This produces the following result.

{"columns":[{"field":"brent","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"yield","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"brent":"0.0428973947420824","yield":"0.0428973950748617"}]}

See Also

BFGS - Broyden-Fletcher-Goldfarb-Shanno (BFGS) method to find the minimum of a functionBRENT - Find the root of a continuous function of one variable

FDERIV - Numerical function differentiation for orders n = 1 to 8 using finite difference approximations

GRAD - Numerically compute the gradient.

HESSIAN - Numerically computer the Hessian matrix

JACOBIAN - Numerically compute the Jacobian matrix

NEWTON - Find the root of a univariate function

SECANT - Find the root of single-variable continuous function.