Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server GRADIENT function


GRAD
Updated: 16 April 2018

Use the scalar function GRAD to numerically compute the gradient of a function

using central finite difference.

Syntax
SELECT [wct].[GRAD] (
   <@Func, nvarchar(max),>
  ,<@VarNames, nvarchar(4000),>
  ,<@X, nvarchar(4000),>
  ,<@H, float,>)
Arguments
Input NameDescription
@FuncThe function to be evaluated, as a string. The function must be in the form of a SELECT statement.
@VarNameThe name of the variable
@XThe starting point for the minimization
@HStep size
Return Type
[nvarchar](max)
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.
  • If @X is NULL then @X = ''.
  • If @H is NULL then @H = 0.
  • If @H <= 0 then @H = .
  • Available in XLeratorDB / math 2008 only
Examples
Example #1

Calculate the gradient of

at the point (1,1,1).

Since the result is returned as a string, we will use the MATRIX function to unpack the results into a vector format.

SELECT
    RowNum,
    ItemValue
FROM wct.MATRIX(
        wct.GRAD(
            'SELECT POWER(@x,3) / POWER(@y,2) * POWER(@z,2) + 12*@x*@y / 2*@z'
            ,'@x,@y,@z'
            ,'1,1,1'
            ,NULL
        )
    )

This produces the following result.

Example #2

Using the same function from the previous formula we use the FDERIV function to demonstrate the calculation of the gradient.

SELECT
     wct.FDERIV(REPLACE(REPLACE('SELECT POWER(@x,3) / POWER(@y,2) * POWER(@z,2) + 12*@x*@y / 2*@z','@y',1),'@z',1),'@x',1,1,NULL,'C') as [dF/dx]
    ,wct.FDERIV(REPLACE(REPLACE('SELECT POWER(@x,3) / POWER(@y,2) * POWER(@z,2) + 12*@x*@y / 2*@z','@x',1),'@z',1),'@y',1,1,NULL,'C') as [dF/dy]
    ,wct.FDERIV(REPLACE(REPLACE('SELECT POWER(@x,3) / POWER(@y,2) * POWER(@z,2) + 12*@x*@y / 2*@z','@x',1),'@y',1),'@z',1,1,NULL,'C') as [dF/dz]

This produces the following result.

See Also


Copyright 2008-2018 Westclintech LLC         Privacy Policy        Terms of Service