|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Derivatives · FiniteDiff.jl</title><script data-outdated-warner src="../assets/warner.js"></script><link rel="canonical" href="https://docs.sciml.ai/FiniteDiff/stable/derivatives/"/><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script><link href="../assets/favicon.ico" rel="icon" type="image/x-icon"/></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../"><img src="../assets/logo.png" alt="FiniteDiff.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="../">FiniteDiff.jl</a></span></div><form class="docs-search" action="../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li><a class="tocitem" href="../tutorials/">Tutorials</a></li><li class="is-active"><a class="tocitem" href>Derivatives</a><ul class="internal"><li><a class="tocitem" href="#Overview"><span>Overview</span></a></li><li><a class="tocitem" href="#Functions"><span>Functions</span></a></li><li><a class="tocitem" href="#Cache"><span>Cache</span></a></li></ul></li><li><a class="tocitem" href="../gradients/">Gradients</a></li><li><a class="tocitem" href="../jacobians/">Jacobians</a></li><li><a class="tocitem" href="../hessians/">Hessians</a></li><li><a class="tocitem" href="../jvp/">Jacobian-Vector Products</a></li><li><a class="tocitem" href="../epsilons/">Step Size Selection</a></li><li><a class="tocitem" href="../utilities/">Internal Utilities</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Derivatives</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Derivatives</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/JuliaDiff/FiniteDiff.jl/blob/master/docs/src/derivatives.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Derivatives"><a class="docs-heading-anchor" href="#Derivatives">Derivatives</a><a id="Derivatives-1"></a><a class="docs-heading-anchor-permalink" href="#Derivatives" title="Permalink"></a></h1><p>Functions for computing derivatives of scalar-valued functions.</p><h2 id="Overview"><a class="docs-heading-anchor" href="#Overview">Overview</a><a id="Overview-1"></a><a class="docs-heading-anchor-permalink" href="#Overview" title="Permalink"></a></h2><p>Derivatives are computed for scalar→scalar maps <code>f(x)</code> where <code>x</code> can be a single point or a collection of points. The derivative functions support:</p><ul><li><strong>Forward differences</strong>: <code>O(1)</code> function evaluation per point, <code>O(h)</code> accuracy</li><li><strong>Central differences</strong>: <code>O(2)</code> function evaluations per point, <code>O(h²)</code> accuracy </li><li><strong>Complex step</strong>: <code>O(1)</code> function evaluation per point, machine precision accuracy</li></ul><p>For optimal performance with repeated computations, use the cached versions with <code>DerivativeCache</code>.</p><h2 id="Functions"><a class="docs-heading-anchor" href="#Functions">Functions</a><a id="Functions-1"></a><a class="docs-heading-anchor-permalink" href="#Functions" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="FiniteDiff.finite_difference_derivative" href="#FiniteDiff.finite_difference_derivative"><code>FiniteDiff.finite_difference_derivative</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">FiniteDiff.finite_difference_derivative( |
| 3 | + f, x::T, |
| 4 | + fdtype::Type{T1}=Val{:central}, |
| 5 | + returntype::Type{T2}=eltype(x), |
| 6 | + f_x::Union{Nothing,T}=nothing)</code></pre><p>Single-point derivative of scalar->scalar maps.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/FiniteDiff.jl/blob/262b06f375b37f66b71595a7d2864e4431830783/src/derivatives.jl#L1-L9">source</a></section><section><div><pre><code class="nohighlight hljs">FiniteDiff.finite_difference_derivative( |
| 7 | + f, |
| 8 | + x :: AbstractArray{<:Number}, |
| 9 | + fdtype :: Type{T1} = Val{:central}, |
| 10 | + returntype :: Type{T2} = eltype(x), # return type of f |
| 11 | + fx :: Union{Nothing,AbstractArray{<:Number}} = nothing, |
| 12 | + epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing; |
| 13 | + [epsilon_factor])</code></pre><p>Compute the derivative <code>df</code> of a scalar-valued map <code>f</code> at a collection of points <code>x</code>.</p><p>Cache-less.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/FiniteDiff.jl/blob/262b06f375b37f66b71595a7d2864e4431830783/src/derivatives.jl#L89-L102">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="FiniteDiff.finite_difference_derivative!" href="#FiniteDiff.finite_difference_derivative!"><code>FiniteDiff.finite_difference_derivative!</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">FiniteDiff.finite_difference_derivative!( |
| 14 | + df :: AbstractArray{<:Number}, |
| 15 | + f, |
| 16 | + x :: AbstractArray{<:Number}, |
| 17 | + fdtype :: Type{T1} = Val{:central}, |
| 18 | + returntype :: Type{T2} = eltype(x), |
| 19 | + fx :: Union{Nothing,AbstractArray{<:Number}} = nothing, |
| 20 | + epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing; |
| 21 | + [epsilon_factor])</code></pre><p>Compute the derivative <code>df</code> of a scalar-valued map <code>f</code> at a collection of points <code>x</code>.</p><p>Cache-less but non-allocating if <code>fx</code> and <code>epsilon</code> are supplied (<code>fx</code> must be <code>f(x)</code>).</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/FiniteDiff.jl/blob/262b06f375b37f66b71595a7d2864e4431830783/src/derivatives.jl#L117-L131">source</a></section><section><div><pre><code class="nohighlight hljs">FiniteDiff.finite_difference_derivative!( |
| 22 | + df::AbstractArray{<:Number}, |
| 23 | + f, |
| 24 | + x::AbstractArray{<:Number}, |
| 25 | + cache::DerivativeCache{T1,T2,fdtype,returntype}; |
| 26 | + relstep=default_relstep(fdtype, eltype(x)), |
| 27 | + absstep=relstep, |
| 28 | + dir=true)</code></pre><p>Compute the derivative <code>df</code> of a scalar-valued map <code>f</code> at a collection of points <code>x</code>.</p><p>Cached.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/FiniteDiff.jl/blob/262b06f375b37f66b71595a7d2864e4431830783/src/derivatives.jl#L147-L160">source</a></section></article><h2 id="Cache"><a class="docs-heading-anchor" href="#Cache">Cache</a><a id="Cache-1"></a><a class="docs-heading-anchor-permalink" href="#Cache" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="FiniteDiff.DerivativeCache" href="#FiniteDiff.DerivativeCache"><code>FiniteDiff.DerivativeCache</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">FiniteDiff.DerivativeCache( |
| 29 | + x :: AbstractArray{<:Number}, |
| 30 | + fx :: Union{Nothing,AbstractArray{<:Number}} = nothing, |
| 31 | + epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing, |
| 32 | + fdtype :: Type{T1} = Val{:central}, |
| 33 | + returntype :: Type{T2} = eltype(x))</code></pre><p>This allocates either <code>fx</code> or <code>epsilon</code> if these are nothing and they are needed. <code>fx</code> is the current call of <code>f(x)</code> and is required for forward-differencing (otherwise is not necessary).</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/FiniteDiff.jl/blob/262b06f375b37f66b71595a7d2864e4431830783/src/derivatives.jl#L42-L53">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../tutorials/">« Tutorials</a><a class="docs-footer-nextpage" href="../gradients/">Gradients »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.25 on <span class="colophon-date" title="Wednesday 13 August 2025 13:01">Wednesday 13 August 2025</span>. Using Julia version 1.11.6.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
0 commit comments