newtonsMethod

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

Performs the Newton’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{f(z_k)}{f'(z_k)}\]

Example

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

Output:

0 + 0j
0 + 0j

References