# 3.3: A First Computer Model

- Page ID
- 25431

\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

\( \newcommand{\Span}{\mathrm{span}}\)

\( \newcommand{\id}{\mathrm{id}}\)

\( \newcommand{\Span}{\mathrm{span}}\)

\( \newcommand{\kernel}{\mathrm{null}\,}\)

\( \newcommand{\range}{\mathrm{range}\,}\)

\( \newcommand{\RealPart}{\mathrm{Re}}\)

\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

\( \newcommand{\Argument}{\mathrm{Arg}}\)

\( \newcommand{\norm}[1]{\| #1 \|}\)

\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)

\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)

\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vectorC}[1]{\textbf{#1}} \)

\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

Below are two lines of computer code forming a program that models the bacterial colony as it doubles every hour. If you have not seen computer code before, don’t be frightened by this; we will go through it carefully below.

**N=1; t=0; **

**while(t<=5*24) { print(N); N=N*2; t=t+1; }**

The above program is written in a generic programming language—it could be run as the programming language R, as the language AWK, or, with minor adjustments as the language C, Java, or a number of others. This particular code is essentially identical in many languages.

The first “statement” is **N=1**. That instructs the computer to set the number of bacteria, **N**, equal to 1. A semicolon (;) ends the statement and separates it from subsequent statements. The next statement is **t=0**. That instructs the computer to set the time **t** to 0. One bacterium at time zero forms the “initial conditions,” and once the computer has finished that line, the program is said to be “initialized.”

The second line of the program is more involved, but can be understood in two parts. The first part on the left, **while(t<=5*24)**, instructs the computer to repeat a set of code for 5 simulated days of 24 hours each. The second part is the code to be repeated, within braces on the right, **{...}**.

Considering the first part, while is a “keyword” that instructs the computer to repeat something until the “condition” in parentheses is no longer true. In this case, inside the parentheses is **t<=5*24**, which itself consists of three parts, **t**, **<=**, and **5*24**. The first part, **t**, represents the time, which has just been initialized to zero in the previous line of code. The second part, **<=**, is the symbol for “less than or equal to.” Six such “comparison” symbols are possible, **==**, **<**, **<=**, **>**, **>=**, and **!=**, representing comparison for equal, less than, less than or equal, greater than, greater than or equal, and not equal, respectively. In the third part, the asterisk (*****) is a symbol for multiplication, so **5*24** means “five times twenty-four,” a way to represent the number 120, or the number of hours from Monday to Friday—the amount of time the hypothesized bacterial culture is to reproduce.

Computer coding is an exacting business, where tiny variations can make huge differences. The computer is the ultimate literal interpreter. An example of this just slipped by in the previous paragraph. In coding, a single equals sign, **=**, means “change something to be equal to,” whereas two consecutive equals signs, **==**, means “compare to see if two things are the same.”

If you are accustomed to coding, you will already be familiar with such subtleties; if this is all new to you, it is something to get used to. Various primers on the web can help, but don’t be discouraged if it seems difficult at first; computer coding turns out to be one of the easiest things to jump into but one of the most difficult areas of all human endeavour to get exactly right. Time and patience will assist.

Getting back to the code, the phrase **while(t<=5*24)** means, in this case, to repeat something as long as the time, **t**, is less than or equal to 120 hours, 5 times 24. And that something to be repeated appears within braces to the right, **{...}**. (By the way, many programming languages use three main symbols for grouping information—called braces, **{ }**, brackets, **[ ]**, and parentheses, **( )**. They are used for various kinds of groupings, but unfortunately their usage is not consistent across all languages.)

The first statement within braces is **print(N)**. (Refer back to the two-line program.) “Print” is a term left from the days when computers would communicate largely by printing on paper. Now the term just means “display.” The statement thus means “display the number of individuals in the population,** N**, at this time.“ That was set to 1 in the previous line, so when the computer runs **print(N)** for the first time, it will display the number 1, typically on your screen.

The next statement, **N=N*2**, is read “**N** equals **N** times two.” It is similar in form to the statement on the first line, **N=1**, which started things off with a single bacterium. The ‘**N=**’ part is the same. It tells the computer that the number of bacteria, **N**, is about to change. (Of course, the computer has no clue what the program is about—that you are running a program about bacteria.) What **N** will change to is immediately to the right of the equal sign, **N*2**. The asterisk (*****) means multiply. So this statement thus tells the computer to double the value of **N**. That is what the hypothesized bacterial population does every hour, so this statement models that doubling.

The third statement on the line, **t=t+1**, is read “**t **equals** t** plus one.” It is similar in form to the statement on the first line, **t=0**, which started things off with a clock time of zero. In other words, in this example of letting bacteria grow for a five-day work week, we are taking midnight Monday morning to be hour zero. Five days later, at midnight Friday night, that becomes hour 120 (5 days times 24 hours per day equals 120 hours). So similarly, **t=** tells the computer that time **t **is about change. Following the equals sign is what it should change to, **t+1**, or one more than what it is at the moment, which advances the time by one hour. This is a *discrete time* model, so it approximates the real system by modeling only specific moments.

Those three statements are run in order, from left to right, first displaying the number of bacteria, then modeling the doubling of the bacterial population, and then advancing to the next hour. By the way, it may have occurred to you that the last two statements could be written in either order, or even run at the same time—they are independent, so the ordering would not matter.

After all three statements are run, your display will contain the number 1, **N** will be **2**, and **t **will be **1**. The computer next examines the code inside the parentheses associated with the keyword **while** to see if the three statements inside the braces should be run again. That condition specifies that as as long as the time** t **is less than or equal to 120, the three statements must be repeated. At this point,** t **is equal to 1, which certainly is less than 120. Therefore the three statements will be run again.

This is called a “loop,” and now the computer will begin the second time around the loop, running the three statements again as they ran before, but now with altered values of **N** and **t**. First it will display **N**, which is now equal to 2, so it will display 2. Then it will double **N** again, changing it from 2 bacteria to 4, and increase the time **t** by 1, from hour 1 to hour 2.

Thus the process repeats. Examining the condition inside the parentheses, the computer finds that 2 is less than or equal to 120, and so the three statements inside braces are run again. This goes on and on until **t** is greater than 120, at which time the loop is finished. At the end, **t** will be 121 and **N** will be whatever number has been reached by the process of doubling.

This code illustrates two fundamental aspects of computer coding: “condition testing” and “looping.” In larger programs loops are “nested” within other loops and condition tests are nested correspondingly. But this two-line program, with the first line initializing and the second line running a loop, is sufficient for our first model. You will soon see that this is not a trivial model, but one that demonstrates an inviolable law of biology, which Darwin put directly to use in creating his theory of evolution.