Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting of episode 16 solution #681

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions episodes/16-writing-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
Loading