Iterate the function "eval_function" exactly nb_iterations times. The first argument of the function is a parameter which is contained in function_params. The variable z_0 is an array that contains the initial values to iterate from. This function returns the final iterates.
(
eval_function: Callable[[Any, np.ndarray], np.ndarray],
function_params: Any,
nb_iterations: int,
z_0: np.ndarray,
infinity: float | None = None,
)
| 83 | |
| 84 | |
| 85 | def iterate_function( |
| 86 | eval_function: Callable[[Any, np.ndarray], np.ndarray], |
| 87 | function_params: Any, |
| 88 | nb_iterations: int, |
| 89 | z_0: np.ndarray, |
| 90 | infinity: float | None = None, |
| 91 | ) -> np.ndarray: |
| 92 | """ |
| 93 | Iterate the function "eval_function" exactly nb_iterations times. |
| 94 | The first argument of the function is a parameter which is contained in |
| 95 | function_params. The variable z_0 is an array that contains the initial |
| 96 | values to iterate from. |
| 97 | This function returns the final iterates. |
| 98 | |
| 99 | >>> iterate_function(eval_quadratic_polynomial, 0, 3, np.array([0,1,2])).shape |
| 100 | (3,) |
| 101 | >>> complex(np.round(iterate_function(eval_quadratic_polynomial, |
| 102 | ... 0, |
| 103 | ... 3, |
| 104 | ... np.array([0,1,2]))[0])) |
| 105 | 0j |
| 106 | >>> complex(np.round(iterate_function(eval_quadratic_polynomial, |
| 107 | ... 0, |
| 108 | ... 3, |
| 109 | ... np.array([0,1,2]))[1])) |
| 110 | (1+0j) |
| 111 | >>> complex(np.round(iterate_function(eval_quadratic_polynomial, |
| 112 | ... 0, |
| 113 | ... 3, |
| 114 | ... np.array([0,1,2]))[2])) |
| 115 | (256+0j) |
| 116 | """ |
| 117 | |
| 118 | z_n = z_0.astype("complex64") |
| 119 | for _ in range(nb_iterations): |
| 120 | z_n = eval_function(function_params, z_n) |
| 121 | if infinity is not None: |
| 122 | np.nan_to_num(z_n, copy=False, nan=infinity) |
| 123 | z_n[abs(z_n) == np.inf] = infinity |
| 124 | return z_n |
| 125 | |
| 126 | |
| 127 | def show_results( |