Differentiation

Introduction

This module provides functions for numerical differentiation of univariate and multivariate functions, $R^n \to R$.

API

NumericalMethods.Deriv.differentiateMethod
differentiate(f::Function, x::Real; δ::Real=1.0e-6, two_side::Bool=true)

Compute the derivative of f at x using a one or two-sided difference quotient.

Arguments

  • f::Function: The function to differentiate.
  • x::Real: The point at which to differentiate f.
  • δ::Real=1.0e-6: The step size to use in the difference quotient.
  • two_side::Bool=true: Whether to use a two-sided difference quotient.

Returns

  • deriv: The derivative of f at x.
source
NumericalMethods.Deriv.gradientMethod
gradient(f::Function, x::AbstractVector; δ::Real=1.0e-6)

Compute the gradient of f at x using a two-sided difference quotient.

Arguments

  • f::Function: The function to differentiate.
  • x::AbstractVector: The point at which to differentiate f.
  • δ::Real=1.0e-6: The step size to use in the difference quotient.

Returns

  • grad::Vector: The gradient of f at x.
source
NumericalMethods.Deriv.hessianMethod
hessian(f::Function, x::AbstractVector; δ::Real=1.0e-6)

Compute the Hessian of f at x using a two-sided difference quotient.

Arguments

  • f::Function: The function to differentiate.
  • x::AbstractVector: The point at which to differentiate f.
  • δ::Real=1.0e-6: The step size to use in the difference quotient.

Returns

  • hess::Matrix: The Hessian of f at x.
source
NumericalMethods.Deriv.partialMethod
partial(f::Function, x::AbstractVector, i::Integer; δ::Real=1.0e-6)

Compute the partial derivative of f at x with respect to the ith component of x using a two-sided difference quotient.

Arguments

  • f::Function: The function to differentiate.
  • x::AbstractVector: The point at which to differentiate f.
  • i::Integer: The index of the component of x with respect to which to differentiate f.
  • δ::Real=1.0e-6: The step size to use in the difference quotient.

Returns

  • deriv: The partial derivative of f at x with respect to the ith component of x.
source
NumericalMethods.Deriv.twice_differentiateMethod
twice_differentiate(f::Function, x::Real; δ::Real=1.0e-6)

Compute the second derivative of f at x using a two-sided difference quotient.

Arguments

  • f::Function: The function to differentiate.
  • x::Real: The point at which to differentiate f.
  • δ::Real=1.0e-6: The step size to use in the difference quotient.

Returns

  • deriv: The second derivative of f at x.
source