SF_DERIVATE
Description
SciFortran module for function differentiation
Quick access
- Routines:
cgradient()
,cjacobian()
,deriv()
,derivative()
,derivative2()
,derivative3()
,derivative4()
,derivativen()
,dgradient()
,djacobian()
,f_cgradient()
,f_cjacobian()
,f_dgradient()
,f_djacobian()
Subroutines and functions
- interface sf_derivate/djacobian(funcv, x, fjac[, ml, mu, epsfcn, m])
This subroutine calculates the \(m \times n\) Jacobian matrix \([\partial \mathrm{funcv}_{i} / \partial x_{j}]\) for a \(\mathrm{funcv} : \mathbb{R}^{n}\rightarrow\mathbb{R}^{m}\) , where \(i \in [1,m]\) and \(j \in [1,n]\). If \(m \neq n\) the dimension
m
of the codomain needs to be passed as a parameter. The subroutine takes the functionfuncv()
to be differentiated as an external procedure, in the form of a subroutine or a function. In the case of a function, it has to be of the formfuncv(x,[m])
returning a real array of dimensionsize(x)
orm
. In the case of a subroutine, it has to be of the formfuncv(x,[m],y)
, wherey
has dimensionsize(x)
orm
. The calculated Jacobian is areal
matrix of dimension \([n,n]\) or \([m,n]\). In the case where the Jacobian matrix is expected to be band-diagonal, the calculation can be sped up by specifying the number of lower and upper subdiagonals to be calculated. This can be done via the optional parametersml
andmu
.- Parameters:
funcv [external] – An external procedure which takes as input an array of
real
x
and returns an array ofreal
x (•) [real, in,required] – An array containing the element in the function domain where the Jacobian matrix is to be calculated
fjac (various shapes) [real] – The Jacobian matrix calculated at
x
- Options:
ml [integer] – Lower subdiagonal limit (number of lower subdiagonals to be calculated)
mu [integer] – Upper subdiagonal limit (number of upper subdiagonals to be calculated)
epsfcn [real] – Step size for the numerical calculation of the Jacobian (default
epsilon(REAL)
)m [integer] – Dimension of the codomain of
funcv()
- interface sf_derivate/dgradient(funcv, x, fjac[, epsfcn])
This subroutine calculates the gradient of \(\mathrm{funcv} : \mathbb{R}^{n}\rightarrow\mathbb{R}\) at a point \(x \in \mathbb{R}^{n}\) . It takes the function
funcv()
to be differentiated as an external procedure, n the form of a subroutine or a function. In the case of a function, it has to be of the formfuncv(x)
returning a real number. In the case of a subroutine, it has to be of the formfuncv(x,y)
, wherey
is real. The calculated gradient is areal
array of dimensionsize(x)
.- Parameters:
funcv [external] – An external procedure which takes as input an array of
real
x
and returns a real numberx (•) [real, in,required] – An array containing the element in the function domain where the gradient is to be calculated
fjac (size(x)) [real] – The gradient vector calculated at
x
- Options:
epsfcn [real] – Step size for the numerical calculation of the Jacobian (default
epsilon(REAL)
)
- interface sf_derivate/f_djacobian(funcv, x, m)
This function calls the
djacobian()
subroutine. The required parameters and returned value follow the same logic. The optional parameters are set as default- Parameters:
funcv [external] – The function of subroutine to be differentiated
x (•) [real, in] – An array containing the element in the function domain where the Jacobian is to be calculated
m [integer] – Dimension of the codomain of
funcv()
(optional)
- Result:
df (various shapes) [real] – The Jacobian matrix
- interface sf_derivate/f_dgradient(funcv, x)
This function calls the
dgradient()
subroutine. The required parameters and returned value follow the same logic. The optional parameters are set as default- Parameters:
funcv [external] – An external procedure which takes as input an array of
real
x
and returns a real numberx (•) [real, in] – An array containing the element in the function domain where the gradient is to be calculated
- Result:
df (size(x)) [real] – The gradient array
- interface sf_derivate/cjacobian(funcv, x, fjac[, ml, mu, epsfcn, m])
This subroutine is the equivalent
djacobian()
subroutine for \(\mathrm{funcv} : \mathbb{R}^{n}\rightarrow\mathbb{C}^{m}\)- Parameters:
funcv [external] – An external procedure which takes as input an array of
real
x
and returns an array ofcomplex
x (•) [real, in,required] – An array containing the element in the function domain where the Jacobian matrix is to be calculated
fjac (various shapes) [complex] – The Jacobian matrix calculated at
x
- Options:
ml [integer] – Lower subdiagonal limit (number of lower subdiagonals to be calculated)
mu [integer] – Upper subdiagonal limit (number of upper subdiagonals to be calculated)
epsfcn [real] – Step size for the numerical calculation of the Jacobian (default
epsilon(REAL)
)m [integer] – Dimension of the codomain of
funcv()
- interface sf_derivate/cgradient(funcv, x, fjac[, epsfcn])
This subroutine is the equivalent
dgradient()
subroutine for \(\mathrm{funcv} : \mathbb{R}^{n}\rightarrow\mathbb{C}\)- Parameters:
funcv [external] – An external procedure which takes as input an array of
real
x
and returns a complex numberx (•) [real, in,required] – An array containing the element in the function domain where the gradient is to be calculated
fjac (size(x)) [complex] – The gradient vector calculated at
x
- Options:
epsfcn [real] – Step size for the numerical calculation of the Jacobian (default
epsilon(REAL)
)
- interface sf_derivate/f_cjacobian(funcv, x, m)
This function calls the
cjacobian()
subroutine. The required parameters and returned value follow the same logic. The optional parameters are set as default- Parameters:
funcv [external] – The function of subroutine to be differentiated
x (•) [real, in] – An array containing the element in the function domain where the Jacobian is to be calculated
m [integer] – Dimension of the codomain of
funcv()
(optional)
- Result:
df (various shapes) [complex] – The Jacobian matrix
- interface sf_derivate/f_cgradient(funcv, x)
This function calls the
cgradient()
subroutine. The required parameters and returned value follow the same logic. The optional parameters are set as default- Parameters:
funcv [external] – An external procedure which takes as input an array of
real
x
and returns a complex numberx (•) [real, in] – An array containing the element in the function domain where the gradient is to be calculated
- Result:
df (size(x)) [complex] – The gradient array
- function sf_derivate/deriv(f, dh)
Calculates the first derivative of a real discretized function. At the first and last points it is calculated at first order of accuracy \(O(dh)\) with forwards and backwards finite differences respectively. At the other points it’s calculated at second order of accuracy \(O(dh^{2})\) with central finite difference.
- Parameters:
f (•) [real, in] – Discretized function to differentiate
dh [real, in] – Spacing
- Result:
df (size(f)) [real] – Discretized derivative of
f
- function sf_derivate/derivative(f, dh[, order])
Improves over
deriv()
. Calculates the first derivative of a real discretized function. The order of accuracy in the differentiation is controlled by the parameterorder
and can be one of the following:1
: \(O(dh)\) forwards (backwards) at first (last) point, \(O(dh^{2})\) centered everywhere else.2
: \(O(dh^{2})\) forwards (backwards) at first (last) point, centered everywhere else.4
: \(O(dh^{4})\) forwards (backwards) at first (last) point, centered everywhere else. Default value.6
: \(O(dh^{6})\) forwards (backwards) at first (last) point, centered everywhere else.
- Parameters:
f (•) [real, in] – Discretized function to differentiate
dh [real, in] – Spacing
- Options:
order [integer, in] – Order of accuracy in the differentiation. Default
4
- Result:
df (size(f)) [real] – Discretized derivative of
f
- function sf_derivate/derivative2(f, dh[, order])
Calculates the second derivative of a real discretized function. The order of accuracy in the differentiation is controlled by the parameter
order
and can be one of the following:1
: \(O(dh)\) forwards (backwards) at first (last) point, \(O(dh^{2})\) centered everywhere else.2
: \(O(dh^{2})\) forwards (backwards) at first (last) point, centered everywhere else.4
: \(O(dh^{4})\) forwards (backwards) at first (last) point, centered everywhere else. Default value.6
: \(O(dh^{6})\) forwards (backwards) at first (last) point, centered everywhere else.
- Parameters:
f (•) [real, in] – Discretized function to differentiate
dh [real, in] – Spacing
- Options:
order [integer, in] – Order of accuracy in the differentiation. Default
4
- Result:
df (size(f)) [real] – Discretized second derivative of
f
- function sf_derivate/derivative3(f, dh[, order])
Calculates the third derivative of a real discretized function. The order of accuracy in the differentiation is controlled by the parameter
order
and can be one of the following:1
: \(O(dh)\) forwards (backwards) at first (last) point, \(O(dh^{2})\) centered everywhere else.2
: \(O(dh^{2})\) forwards (backwards) at first (last) point, centered everywhere else.4
: \(O(dh^{4})\) forwards (backwards) at first (last) point, centered everywhere else. Default value.6
: \(O(dh^{6})\) forwards (backwards) at first (last) point, centered everywhere else.
- Parameters:
f (•) [real, in] – Discretized function to differentiate
dh [real, in] – Spacing
- Options:
order [integer, in] – Order of accuracy in the differentiation. Default
4
- Result:
df (size(f)) [real] – Discretized third derivative of
f
- function sf_derivate/derivative4(f, dh[, order])
Calculates the fourth derivative of a real discretized function. The order of accuracy in the differentiation is controlled by the parameter
order
and can be one of the following:1
: \(O(dh)\) forwards (backwards) at first (last) point, \(O(dh^{2})\) centered everywhere else.2
: \(O(dh^{2})\) forwards (backwards) at first (last) point, centered everywhere else.4
: \(O(dh^{4})\) forwards (backwards) at first (last) point, centered everywhere else. Default value.6
: \(O(dh^{6})\) forwards (backwards) at first (last) point, centered everywhere else.
- Parameters:
f (•) [real, in] – Discretized function to differentiate
dh [real, in] – Spacing
- Options:
order [integer, in] – Order of accuracy in the differentiation. Default
4
- Result:
df (size(f)) [real] – Discretized fourth derivative of
f
- function sf_derivate/derivativen(f, dh, n)
Calculates the
n
-th derivative of a real discretized function with accuracy \(O(dh^{6})\)- Parameters:
f (•) [real, in] – Discretized function to differentiate
dh [real, in] – Spacing
n [integer, in] – Order of the derivative
- Result:
df (size(f)) [real] – Discretized
n
-th derivative off