Complex Step Derivative Approximation
📂Numerical AnalysisComplex Step Derivative Approximation
The derivative f′(x) of the function f:R→R can be approximated using complex numbers as follows.
f′(x)≈hIm(f(x+ih))
Here, Im represents the imaginary part of the complex number, and h is a sufficiently small real number.
Explanation
Complex analysis continues to be fascinating the more you learn about it. Unlike the finite difference method, which approximates derivatives through multiple function values, this method approximates the derivative of f by formally treating it like a complex function, even if it wasn’t a complex function.
Derivation
There are two methods, both remarkably intriguing. Let’s represent the real number x,y∈R as the complex number z=x+iy, and the real function f:R→R as f(z)=u(z)+iv(z) in terms of u,v:C→R.
Cauchy-Riemann Equations
Cauchy-Riemann Equations: Suppose the function f:A⊆C→C is analytic at R. If the real function u,v satisfies
f(z)=f(x+iy)=u(x,y)+iv(x,y)
then the partial derivatives of u,v with respect to x,y exist and satisfy the following system of differential equations at all points on R.
{ux(x,y)=vy(x,y)uy(x,y)=−vx(x,y)
If f is analytic, then f=u+iv must satisfy the Cauchy-Riemann equations.
∂x∂u=∂y∂u=∂y∂v−∂x∂v
Rewriting the right-hand side of ux, which is vy, in limit form gives the following.
∂x∂u=h→0limhv(x+i(y+h))−v(x+iy)
Though f is formally treated like a complex function, it is inherently a real function. Thus, y=0 and v(x)=0 are valid, and u(x) is indeed u(x)=f(x). Substituting them one by one, with y=0, we have
∂x∂u=h→0limhv(x+ih)−v(x)
and with v(x)=0, we have
∂x∂u=h→0limhv(x+ih)
Finally, f=u+iv leads to Imf=v, and for a sufficiently small h, we obtain the following formula.
∂x∂f=h→0limhImf(x+ih)≈hImf(x+ih)
■
Taylor Expansion
Taylor Expansion: If the function f(x) is continuous at [a,b] and n differentiable at (a,b), then there exists ξ∈(a,b) satisfying
f(b)==k=0∑n−1k!(b−a)kf(k)(a)+n!(b−a)nf(n)(ξ)f(a)+(b−a)f′(a)+⋯+(n−1)!(b−a)n−1f(n−1)(a)+(n)!(b−a)nf(n)(ξ)
Performing a Taylor expansion from f(x) to ih yields the following.
f(x+ih)=f(x)+ihf′(x)−h22!f′′(x)−ih33!sf′′′(x)+⋯
Since we are interested in f′(x), focusing on the imaginary part gives
Imf(x+ih)=hf′(x)−h33!sf′′′(x)+⋯
and canceling h results in
hImf(x+ih)=f′(x)+O(h2)
Similarly, if h is sufficiently small, h2 becomes negligible, providing the following approximation.
hImf(x+ih)≈f′(x)
■