Paths

class cxroots.Paths.ComplexPath[source]

A base class for paths in the complex plane.

integrate(f, absTol=0, relTol=1e-12, divMax=15, intMethod='quad', verbose=False)[source]

Integrate the function f along the path. The value of the integral is cached and will be reused if the method is called with same arguments (ignoring verbose).

Parameters:
  • f (function) – A function of a single complex variable.
  • absTol (float, optional) – The absolute tolerance for the integration.
  • relTol (float, optional) – The realative tolerance for the integration.
  • divMax (int, optional) – If the Romberg integration method is used then divMax is the maximum number of divisions before the Romberg integration routine of a path exits.
  • intMethod ({'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.
  • verbose (bool, optional) – Passed ass the show argument of scipy.integrate.romberg().
Returns:

The integral of the function f along the path.

Return type:

complex

Notes

This function is only used when checking the multiplicity of roots. The bulk of the integration for rootfinding is done with cxroots.CountRoots.prod().

plot(N=100, linecolor='C0', linestyle='-')[source]

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

Parameters:
  • N (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(saveFile=None, **plotKwargs)[source]

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

Parameters:
  • saveFile (str (optional)) – If given then the plot will be saved to disk with name ‘saveFile’. If saveFile=None the plot is shown on-screen.
  • **plotKwargs – Other key word arguments are passed to plot().
trap_values(f, k, useCache=True)[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\).
  • useCache (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, b)[source]

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

..math:

z(t) = a + (b-a)t, \quad 0\leq t \leq 1
Parameters:
  • a (float) –
  • b (float) –
__call__(t)[source]

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)[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, R, t0, dt)[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)[source]

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)[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