BIOS1100 H17 uke 3
Ukens forelesning
- noen praktiske ting
- begrepsforståelse kapittel 2
- utvalgte øvelser
- nytt stoff uke 3
Læringsmål uke 2
Biologi- kunne forklare hvordan bakterier formerer seg
- kunne de forkjellige faser i bakteriell vekst
- kunne visualisere et enkelt datasett
- kunne lagre visualiseringen i en fil
- kunne last inn et enkelt datasett fra fil
- kunne bruke lister i python
- kunne beskrive en lineær figur i rommet matematisk
- være i stand til å utlede vekstrate og doblingstid for eksponesiell bakterievekst
En del praktiske ting
- obliger: tidspunkter
- celler i notebook
- hva er en python pakke?
Exercise 1: List slicing (1)
Fill in the blank to achieve the desired output
bases = ["A", "C", "G", "T"]
AT_basepair = [bases[_], bases[_]]
print(AT_basepair)
[A,T]
-
A
,T
-
0
,3
-
1
,4
-
0
,-1
Solution.
- It is the index of the desired element that you need, and not the desired element.
- Correct - the first element's index is 0 and the last element's index is 3.
- Elements A and T are the desired elements. A is in the first place and index of the first element is 0 and not 1. Therefore, index of the last element is not 4, but 3.
- Correct - index of the first element, which is A, is 0 and no matter how long the list is, element with index
-1
is always the last element of the list.
Exercise 2: List slicing (2)
list = [0, 2, 4, 6, 8, 10]
Which of the following would give the list [2, 4, 6]
?
-
list[1:3]
-
list[1:4]
-
list[2, 4, 6]
-
list[0:3]
Solution.
- This gives: [2, 4]. When indexing , elment with index "to" is not included.
- Correct. Element "2" has index 1 and element "6" has index 3. Since element with index 4 is not included in slicing, we will get elements with indexes 1, 2 and 3, which gives [2, 4, 6].
- This gives TypeError. You can have list[2], list[4] or list[6] in general (in this case list[6] does not exist since our list has only 6 elements - last element has index 5), or in slice form, which is list[from:to], but list[a, b, c] cannot be used.
- This gives: [0, 2, 4]. Look at the solution above (point 2).
Exercise 3: List slicing (3)
What is the output of following program?
list1 = [1, 2, 3, 4, 5, 6]
list2 = list1[-2:]
print(list2)
-
[5, 6]
-
[1, 2, 3, 4, 5]
-
[5]
-
[6]
Solution.
Exercise 4: List slicing (4)
What is the output of following code?
list1 = [10, 12, 16, 23, 54, 3]
print(len(list1[1:5]))
-
4
-
5
-
3
-
1
Solution.
Function len()
counts the number of elements in a given list, array, dictionary, etc (more about arrays and dictionaries in later chapters). In this case, [1:5]
takes into account the second element (index 1) and second last element (index 4). It does not take into account element with index 5, but one before that. Therefore, the answer is 4.
Exercise 5: Logarithms
a) What is \( \log_2(2^3) \)
- 1
- 2
- 3
- 8
Solution. By definition, the logarithm with base \( x \) of \( x^n \) is \( n \), or \( \log_x (x^n) = n \)
Utvalgte øvelser
- Exercise 3: Death phase: decline rate
- Exercise 7: Oldest people in the world
- Exercise 8: Volume of a sphere and Bergmann's rule
Læringsmål uke 3
Matematikk
- kunne lage og implementer et enkelt eksponesiell vekst modell
- kunne sammenligne resulater fra modellen med eksperimentelle data
- kunne forklare begrensninger med eksponesiell vekst modellen
- Numpy arrays
-
for
løkker
Parring
Vi begynner med 1 student som står mens resten sitter. Vi gjør følgende:
- hver runde finner hver student som står en partner
- alle nye partnere skal stå opp også
--> Mentimeter
Hvorfor modellering
- simulering
- predikering
- billig og trygt eksperiment
- eksempler
- klimamodeller
- sykdomsspredning
- torskebestander
Hvordan modellering
- matematisk modell
- sett med regler
- implementering
- beregningsmodell
- algoritme
Matematisk modell
Matematisk modell
After each time step, we have twice as many bacteria. $$ \begin{equation} E_n = 2E_{n-1}. \label{_auto1} \end{equation} $$
Implementering
Python
- Numpy arrays
- som lister, men mer egnet for mattematikk
-
for
løkker - jobbe effektivt med lister, arrays mm
Repetisjon
In programming, there is a rule of thumb called ''the rule of three''. It states that if a task has to be repeated three times or more, we should automate it.
- manuell repetisjon er tidskrevende
- manuell repetisjon kan lett bli en feilkilde
For loops
numbers_list = [7, 2, 4, 3]
print(numbers[0])
print(numbers[1])
print(numbers[2])
print(numbers[3])
Eller
numbers_list = [7, 2, 4, 3]
for number in numbers_list:
print(number)
Volume of a sphere and Bergmann's rule
Calculate the ratio \( \frac{Surface Area}{Volume} \), for the following radiuses:
0.5, 1, 1.5, 2, 2.5, 3, 3.5 and 4 meter.
Store the results in two different lists called radiuses
and ratios
.
Start the ratios
list as an empty list:
ratios = []
Then add the ratios each time you calculate them using the ratios.append()
function.
Growth model for E. coli
After each time step, we have twice as many bacteria. $$ \begin{equation} E_n = 2E_{n-1}. \label{_auto2} \end{equation} $$
Growth model for E. coli
$$ \begin{align} E_n &= 2E_{n-1}, \label{_auto3}\\ t_n &= t_{n-1} + \Delta t, \label{_auto4} \end{align} $$
for n in range(1, N):
E[n] = 2*E[n-1]
t[n] = t[n-1] + delta_t
Python versus matte
$$ \begin{equation} x = x + 1. \label{_auto5} \end{equation} $$
x = 12
x = x + 1
print(x)
13