derivative

constexpr Complex derivative(Complex (*f)(Complex), const Complex &z) noexcept

Evaluates the derivative of a complex function at a point \(z\). The derivative is implemented using finite differences [1].

Parameters

Complex (*f)(Complex)

The function to differentiate.

const Complex &z

A complex number.

Returns

type Complex

A complex number.

This function simply returns the derivative of a function \(f\) evaluated at a point \(z\), that is:

\[\left. \frac{df(x)}{dx} \right|_{x = z} = \lim_{h\to 0} \frac{f(z + h) - f(z - h)}{2h}\]

To approxiate the derivative, we set \(h = 10^{-8}\).

Example

auto fn = [](Complex z) { return sin(z); };
std::cout << derivative(fn, 1 + 1_j) << "\n";
std::cout << cos(1 + 1_j) << "\n";

Output:

0.83373 - 0.988898j
0.83373 - 0.988898j

References