Action:
|
Computes the numerical derivative of a law function with respect to a given variable, a given number of times.
|
|
Filename:
|
kern/kern_scm/law_scm.cxx
|
|
APIs:
|
api_ndifferentiate_law
|
|
Syntax:
|
(law:nderivative law value [with-respect-to
|
|
|
[number-of [type=0]]])
|
|
Arg Types:
|
law
|
law | string | real | position |
|
|
|
par-pos | gvector
|
|
value
|
(entity | (entity ...)) | real |
|
|
|
position | gvector | par-pos
|
|
with-respect-to
|
law
|
|
number-of
|
integer
|
|
type
|
integer
|
|
Returns:
|
real
|
|
Description:
|
The
law:nderivative returns the numerical derivative of the given
law function at the specified value,
value.
|
|
|
law specifies a law.
|
|
|
value specifies a value at which the derivative is evaluated.
|
|
|
with-respect-to is an optional argument specifying an identity law, such as x, y, z, or a#, etc. If
with-respect-to is provided, then the derivative is performed with respect to this argument; else the derivative is assumed to be with respect to
x or
a1.
|
|
|
If
number-of is specified as some integer, then the extension performs multiple derivatives. If
number-of is not specified, it is assumed to be 1.
|
|
|
type defines the type of derivative. Zero is normal (default); 1 is from the left; and 2 is from the right.
|
|
Example:
|
; law:nderivative
|
|
; Define a law to use.
|
|
(define law1 (law "x^2"))
|
|
;; law1
|
|
; Find the numerical derivative at 3.
|
|
(law:nderivative law1 3 "x" 1)
|
|
;; 5.9999999999838
|
|
; Find the second numerical derivative at 3.
|
|
(law:nderivative law1 3 "x" 2)
|
|
;; 1.9999997294066
|
|
; To get exact results, take the exact derivative.
|
|
; Create the derivative of that law.
|
|
(define dlaw (law:derivative law1))
|
|
;; dlaw
|
|
; Evaluate the derivative.
|
|
(law:eval dlaw 3)
|
|
;; 6
|
|
|
; Example of left and right derivatives.
|
|
(law:nderivative "abs(x)" 0 "x" 1 1)
|
|
;; -1
|
|
(law:nderivative "abs(x)" 0 "x" 1 2)
|
|
;; 1
|
|
(law:nderivative "abs(x)" 0 "x" 1 0)
|
|
;; -1.52465930505774e-16
|
|
; In the case of non-differentiable functions,
|
|
; the normal option returns the average value.
|