From fe0fb1121f4293d43bf49b248576cb36d44c25be Mon Sep 17 00:00:00 2001 From: danny-lloyd Date: Tue, 11 Jun 2024 09:52:35 +0100 Subject: [PATCH] Improve formatting of episode 16 solution Simulating a dynamical system solution had a new line in the code block which caused the whole block not to be rendered. --- episodes/16-writing-functions.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/episodes/16-writing-functions.md b/episodes/16-writing-functions.md index 613850f9b..a2f599d0f 100644 --- a/episodes/16-writing-functions.md +++ b/episodes/16-writing-functions.md @@ -573,21 +573,25 @@ density. In the model, time takes discrete values 0, 1, 2, ... ## Solution -1. ```python +1. + ```python def logistic_map(x, r): return r * x * (1 - x) ``` -2. ```python +2. + ```python initial_population = 0.5 t_final = 10 r = 1.0 population = [initial_population] + for t in range(t_final): population.append( logistic_map(population[t], r) ) ``` -3. ```python +3. + ```python def iterate(initial_population, t_final, r): population = [initial_population] for t in range(t_final): @@ -598,7 +602,7 @@ density. In the model, time takes discrete values 0, 1, 2, ... population = iterate(0.5, period, 1) print(population[-1]) ``` - + ```output 0.06945089389714401 0.009395779870614648