secondDerivative

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

Evaluates the second derivative of a complex function at a point \(z\). The second 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 second derivative of a function \(f\) evaluated at a point \(z\), that is:

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

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

Example

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

Output:

-0.83373 + 0.988898j
-0.83373 + 0.988898j

References