 # SQL Server SECANT function

SECANT
Updated: 15 April 2018

Use the scalar function SECANT to find the root of a univariate function.

Syntax
SELECT [wct].[SECANT] (
<@Func, nvarchar(max),>
,<@VarName, nvarchar(4000),>
,<@A, float,>
,<@B, float,>
,<@MaxIter, int,>
,<@tol, float,>)
Arguments
 Input Name Description @Func The function to be evaluated, as a string. The function must be in the form of a SELECT statement. @VarName The name of the variable @A One of the 2 starting values @B Another starting value @MaxIter Maximum number of iterations @tol Absolute tolerance
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.
• If @tol <= 0 then @tol = 0.0000000149011612
• Available in XLeratorDB / math 2008 only
Examples
Example #1

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

SELECT
wct.SECANT(
'SELECT (63 * POWER(@x,5) - 70 * POWER(@x,3) + 15 * @x)/8e+00'
,'@x'
,0.9
,1.0
,NULL
,NULL
) as SECANT

This produces the following result.

Example #2

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

SELECT
wct.SECANT(
'SELECT wct.PRICE(
''2018-04-25''
,''2025-05-15''
,.04
,@Y
,100
,2
,0) - 98.25'
,'@Y'
,.04
,.12
,NULL
,1E-08
) as secant
,wct.YIELD(
'2018-04-25'
,'2025-05-15'
,.04
,98.25
,100
,2
,0) as yield

This produces the following result.  Copyright 2008-2021 Westclintech LLC         Privacy Policy        Terms of Service