fractpy.models package¶
Submodules¶
fractpy.models.newton module¶
- class fractpy.models.newton.NewtonFractal(func, prec_goal=1e-11, nmax=200)[source]¶
A class for plotting Newton Fractal for a given function.
Newton fractals are fractals created in the plane of complex numbers. An iteration process with Newton’s method (or Newton-Raphson Method) is started at each point on a grid in the complex plane, and a color is assigned to each point according to which of the roots of a given function the iteration converges to. [Sahari, M. and Djellit, I., 2006. Fractal Newton basins. Discrete Dynamics in Nature and Society, 2006, pp.1-16.]
- Parameters
func (
sympy
expression) – The function for which we want to plot fractal (single- variable).prec_goal (float, optional) – Tolerance for how small the iteration step be relative to the point to break the loop for that point i.e. if relative difference of the iteration step and the point is smaller than this value, it will stop the loop for this point.
nmax (int, optional) – Number of iterations to be run (default is 200). Minimum recommended value is 50, but for some functions may required over 500.
- function¶
The function for which the Newton Fractal is being generated.
- Type
fractpy.Function
- roots_list¶
Roots of the function.
- Type
list
Example
To plot Newton Fractal for f(x) = x**4 - 2x**3 + 10 we first make a model, and then plot it in required range and resolution:
>>> model = NewtonFractal("x**4 - 2x**3 + 10") >>> p = model.plot(-2, 2, -2, 2, (200, 200))
Where
p
is an object ofmatplotlib.figure.Figure
.To make a plot which can be zoomed use
model.zoom_plot()
.See also
fractpy.Function
A class for performing basic calculus operations on a function (like finding roots).
- plot(xstart, xend, ystart, yend, dim=(100, 100))[source]¶
Plots the fractal for given range and dimensions.
- Parameters
xstart (float) – Lower limit of x-axis
xend (float) – Upper limit of x-axis
ystart (float) – Lower limit of y-axis
yend (float) – Upper limit of y-axis
dim (list of int, optional) – The dimensions of the plot to be generated (resolution of the plot, width X height)(default is (100, 100)).
- Return type
matplotlib.figure.Figure
- zoom_plot(xstart, xend, ystart, yend, dim=(100, 100))[source]¶
Plots the fractal in two identical panels. Zooming in on the right panel will show a rectangle in the first panel, denoting the zoomed region.
- Parameters
xstart (float) – Lower limit of x-axis
xend (float) – Upper limit of x-axis
ystart (float) – Lower limit of y-axis
yend (float) – Upper limit of y-axis
dim (list of int, optional) – The dimensions of the plot to be generated (resolution of the plot, width X height)(default is (100, 100)).
- Return type
matplotlib.figure.Figure