# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.differentiation.multivariate

## Class MultivariateFiniteDifference

• All Implemented Interfaces:
Function<Vector,Double>, RealScalarFunction

public class MultivariateFiniteDifference
extends AbstractRealScalarFunction
A partial derivative of a multivariate function is the derivative with respect to one of the variables with the others held constant. This implementation applies recursively the (first order) finite difference on the function. For example, ${\partial^2 \over \partial x_1 \partial x_2} = {\partial \over \partial x_2}({\partial \over \partial x_1})$ Each of the two univariate derivatives is computed using the central difference method.

• ### Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.analysis.function.Function

Function.EvaluationException
• ### Constructor Summary

Constructors
Constructor and Description
MultivariateFiniteDifference(RealScalarFunction f, int[] varidx)
Construct the partial derivative of a multi-variable function.
• ### Method Summary

All Methods
Modifier and Type Method and Description
Double evaluate(Vector x)
Evaluate numerically the partial derivative of f at point x.
double evaluate(Vector x, double h)
Evaluate numerically the partial derivative of f at point x with step size h.
• ### Methods inherited from class com.numericalmethod.suanshu.analysis.function.rn2r1.AbstractRealScalarFunction

dimensionOfDomain, dimensionOfRange
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### MultivariateFiniteDifference

public MultivariateFiniteDifference(RealScalarFunction f,
int[] varidx)
Construct the partial derivative of a multi-variable function.

For example, varidx = new int[]{1, 2} means $f_{x_1,x_2} = {\partial^2 \over \partial x_1 \partial x_2} = {\partial \over \partial x_2}({\partial \over \partial x_1})$

Parameters:
f - the real multivariate function to take derivative of
varidx - the variable indices of the derivative, counting from 1 up to the domain dimension of f
• ### Method Detail

• #### evaluate

public Double evaluate(Vector x)
Evaluate numerically the partial derivative of f at point x.

Make sure that h and x+h are representable in floating point precision so that the difference between x+h and x is exactly h.

Parameters:
x - the point to evaluate the derivative at
Returns:
the numerical partial derivative of f at point x
public double evaluate(Vector x,
double h)
x - the point to evaluate the derivative of f at
h - the step size