← Back to course
Intro to CS 9-10 / Week 10 / Thursday
4/6
Week 10 · Data, Compression and Models

Thursday

Growing plants on paper
// Shrinking photos, cleaning logs and simulating growth
⏱ about 20 min

Thursday: Growing Plants on Paper

The plant team asks a big question. "If we plant new tomatoes today, how tall might they be in a week?"

Comet groans. "We cannot wait a week to find out. They need an answer today."

Wren opens the growth log. "What do you notice? Each tomato grew a little every day, but never the same amount."

"So we build a pretend tomato," Comet says. "In pseudocode."

Nova dips toward the log. "Then decide what your pretend tomato keeps, and what it leaves out," she says.

Comet starts writing a REPEAT loop. Wren starts listing everything a real tomato needs.

Simulations and models

A simulation is an abstraction of a more complex object or process, built for a specific purpose.

Building one means removing details or simplifying how things work.

Simulations are most useful when real experiments are impractical, for example too slow or too big.

A model makes predictions from chosen data and features. The amount, quality and variety of that data affect how good the model is.

Predictions are tested to check, or validate, a model.

WHY SIMULATE?
  • Read the question.
  • Tap your answer.
Why is a simulation useful for the tomato question?
What does building a simulation always involve?
How do you check whether a model is any good?

Random growth

Real plants grow by different amounts each day. A simulation can use random numbers to copy that variety.

RANDOM(a, b) gives a whole number from a to b, and each one is equally likely. So each run can come out different.

Here is the crew's tomato simulation. The height starts at 10 and grows by 1, 2 or 3 each day.

height ← 10
REPEAT 7 TIMES
{
   growth ← RANDOM(1, 3)
   height ← height + growth
}
DISPLAY(height)
TRACE THE SIMULATION
  • Read the question.
  • Tap your answer.
What is the smallest height this program could display?
What is the largest height it could display?
Comet runs it twice and gets 24, then 22. What happened?
What does RANDOM(1, 3) never return?

What got left out?

Simulations can carry bias from the real-world parts that were included or left out.

The crew's tomato grows every day no matter what. It ignores light, water and temperature.

So it could predict a tall tomato even for a plant left in the dark.

StatementTrue or false?
The tomato simulation uses light readings.?
Leaving out water could make the predictions too hopeful.?
Every run of this simulation gives the same height.?
A simulation is an abstraction of something more complex.?
WHY THIS EXERCISEKnowing what a model leaves out tells you when not to trust it.
Which pseudocode procedure gives the tomato a different growth each day? Type its name.
WHY THIS EXERCISERandom values let a simulation copy the variety of real growth.
Try it
Run the simulation by hand with a six-sided die. Roll it seven times.
A roll of 1 or 2 means growth 1. A roll of 3 or 4 means growth 2. A roll of 5 or 6 means growth 3.
Start at 10 and add each growth. What height do you get?
To copy the variety of real growth, a simulation can use ____ numbers.
Checking a model by testing its predictions is called ____ the model.
On paper, make a line graph of one simulated week: day 0 to day 7 along the bottom, height up the side.

Strong modeling. Tomorrow is Impact Friday: what Beacon data could reveal about the crew.

← Wednesday