halleysMethod

constexpr Complex halleysMethod(Complex (*f)(Complex), const Complex &z0, const double alpha, const int epochs) noexcept

Performs the Halley’s method algortihm on a complex function.

Parameters

Complex (*f)(Complex)

The function to root-find.

const Complex &z0

The starting point.

const int epochs

The number of iterations.

Returns

type Complex

A complex number.

This function root-finds the given complex function \(f\) using the following update rule:

\[z_{k+1} = z_k - \frac{2f(z_k)f'(z_k)}{2[f'(z_k)]^2 - f(x_k)f''(z_k)}\]

Example

auto fn = [](Complex z) { return sin(z); };
Complex z = halleysMethod(fn, 0.1, 1000);
std::cout << z << "\n";
std::cout << sin(z) << "\n";

Output:

0 + 0j
0 + 0j

References