Paths

class cxroots.paths.ComplexPath[source]

A base class for paths in the complex plane.

integrate(f: AnalyticFunc, abs_tol: float = 1.49e-08, rel_tol: float = 1.49e-08, div_max: int = 15, int_method: Literal['quad', 'romb'] = 'quad') complex[source]

Integrate the function f along the path.

\[\oint_C f(z) dz\]

The value of the integral is cached and will be reused if the method is called with same arguments.

Parameters:
  • f (function) – A function of a single complex variable.

  • abs_tol (float, optional) – The absolute tolerance for the integration.

  • rel_tol (float, optional) – The realative tolerance for the integration.

  • div_max (int, optional) – If the Romberg integration method is used then div_max is the maximum number of divisions before the Romberg integration routine of a path exits.

  • int_method ({'quad', 'romb'}, optional) – If ‘quad’ then scipy.integrate.quad() is used to compute the integral. If ‘romb’ then Romberg integraion, using scipy.integrate.romberg(), is used instead.

Returns:

The integral of the function f along the path.

Return type:

complex

plot(num_points: int = 100, linecolor: str | Tuple[float, float, float] | Tuple[float, float, float, float] = 'C0', linestyle: str = '-') None[source]

Uses matplotlib to plot, but not show, the path as a 2D plot in the Complex plane.

Parameters:
  • num_points (int, optional) – The number of points to use when plotting the path.

  • linecolor (optional) – The colour of the plotted path, passed to the matplotlib.pyplot.plot() function as the keyword argument of ‘color’. See the matplotlib tutorial on specifying colours.

  • linestyle (str, optional) – The line style of the plotted path, passed to the matplotlib.pyplot.plot() function as the keyword argument of ‘linestyle’. The default corresponds to a solid line. See matplotlib.lines.Line2D.set_linestyle() for other acceptable arguments.

show(save_file: str | None = None, **plot_kwargs) None[source]

Shows the path as a 2D plot in the complex plane. Requires Matplotlib.

Parameters:
  • save_file (str (optional)) – If given then the plot will be saved to disk with name ‘save_file’. If save_file=None the plot is shown on-screen.

  • **plot_kwargs – Other key word args are passed to plot()

trap_values(f: AnalyticFunc, k: int, use_cache: bool = True) ndarray[Any, dtype[complex128]][source]

Compute or retrieve (if cached) the values of the functions f at \(2^k+1\) points along the contour which are evenly spaced with respect to the parameterisation of the contour.

Parameters:
  • f (function) – A function of a single complex variable.

  • k (int) – Defines the number of points along the curve that f is to be evaluated at as \(2^k+1\).

  • use_cache (bool, optional) – If True then use, if available, the results of any previous calls to this function for the same f and save any new results so that they can be reused later.

Returns:

The values of f at \(2^k+1\) points along the contour which are evenly spaced with respect to the parameterisation of the contour.

Return type:

numpy.ndarray

Line

class cxroots.paths.ComplexLine(a: complex, b: complex)[source]

A straight line \(z\) in the complex plane from points a to b parameterised by

..math:

z(t) = a + (b-a)t, \quad 0\leq t \leq 1
__call__(t: float) complex[source]
__call__(t: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[complex128]]

The function \(z(t) = a + (b-a)t\).

Parameters:

t (float) – A real number \(0\leq t \leq 1\).

Returns:

A point on the line in the complex plane.

Return type:

complex

distance(z: complex) float[source]

Distance from the point z to the closest point on the line.

Parameters:

z (complex) –

Returns:

The distance from z to the point on the line which is closest to z.

Return type:

float

Circular Arc

class cxroots.paths.ComplexArc(z0: complex, R: float, t0: float, dt: float)[source]

A circular arc \(z\) with center z0, radius R, initial angle t0 and change of angle dt. The arc is parameterised by

..math:

z(t) = R e^{i(t0 + t dt)} + z0, \quad 0\leq t \leq 1
Parameters:
  • z0 (complex) –

  • R (float) –

  • t0 (float) –

  • dt (float) –

__call__(t: float) complex[source]
__call__(t: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[complex128]]

The function \(z(t) = R e^{i(t_0 + t dt)} + z_0\).

Parameters:

t (float) – A real number \(0\leq t \leq 1\).

Returns:

A point on the arc in the complex plane.

Return type:

complex

distance(z: complex) float[source]

Distance from the point z to the closest point on the arc.

Parameters:

z (complex) –

Returns:

The distance from z to the point on the arc which is closest to z.

Return type:

float