Skip to content

Commit 9952916

Browse files
authored
Merge pull request #104 from rossbar/vectorize-fractals
Vectorize example applying iterative function analysis to specific values
2 parents 1fecd19 + 7192e87 commit 9952916

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

content/tutorial-plotting-fractals.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,23 @@ Given the shape of our first two plots, we would expect that these values would
161161

162162
```{code-cell} ipython3
163163
selected_values = np.array([0.4 + 0.4j, 0.41 + 0.4j, 0.4 + 0.41j])
164-
for cur_val in selected_values:
164+
num_iter = 9
165165
166-
outputs = np.zeros(10, dtype=complex)
167-
outputs[0] = cur_val
166+
outputs = np.zeros((num_iter+1, selected_values.shape[0]), dtype=complex)
167+
outputs[0] = selected_values
168168
169-
for i in range(9):
170-
outputs[i+1] = f(outputs[i]) # Apply 10 iterations, save each output
169+
for i in range(num_iter):
170+
outputs[i+1] = f(outputs[i]) # Apply 10 iterations, save each output
171171
172-
index = np.linspace(0, 10, 10)
172+
fig, axes = plt.subplots(1, selected_values.shape[0], figsize=(16, 6))
173+
axes[1].set_xlabel('Real axis')
174+
axes[0].set_ylabel('Imaginary axis')
173175
174-
fig = plt.figure(figsize=(5, 5))
175-
ax = plt.axes()
176-
177-
ax.set_xlabel('Real axis')
178-
ax.set_ylabel('Imaginary axis')
179-
ax.set_title(f'Mapping of iterations on {cur_val}')
176+
for ax, data in zip(axes, outputs.T):
177+
cycle = ax.scatter(data.real, data.imag, c=range(data.shape[0]), alpha=0.6)
178+
ax.set_title(f'Mapping of iterations on {data[0]}')
180179
181-
cycle = ax.scatter(np.real(outputs), np.imag(outputs), c=index, alpha=0.6)
182-
fig.colorbar(cycle, label='Iteration');
180+
fig.colorbar(cycle, ax=axes, location="bottom", label='Iteration');
183181
```
184182

185183
To our surprise, the behaviour of the function did not come close to matching our hypothesis. This is a prime example of the chaotic behaviour fractals possess. In the first two plots, the value "exploded" on the last iteration, jumping way beyond the region that it was contained in previously. The third plot on the other hand remained bounded to a small region close to the origin, yielding completely different behaviour despite the tiny change in value.

0 commit comments

Comments
 (0)