Week 3.5: Visualizing Complexity

Capturing the Loop in a Graph

"If a loop is the engine, the graph is the dashboard."

Visualizing Iterative Logic

Objective: Students will learn to store data generated inside a loop into a list and plot the results to visualize air resistance.

The Concept: The "Data Bucket" (15 mins)

  • The Physics Link: Every "tick" of our simulation is a data point. To graph it, we need to save those points.

  • Code Literacy: Using .append().

    • If height_list = [] is an empty bucket, height_list.append(y) drops the current height into that bucket every time the loop runs.
  • The Pattern: 1. Create empty lists. 2. Run the loop. 3. .append() the new values inside the loop. 4. Plot the lists after the loop finishes.

Storing values as the clock ticks

In Week 3, we printed numbers. In Week 3.5, we save them.

height_list = [] # An empty list (the bucket)

# Inside the loop:
height_list.append(y) # Add the current height to the bucket

Deconstructing the "Simulation + Plot" Script (15 mins)

import matplotlib.pyplot as plt

# 1. Setup
y, v, g, dt = 100, 0, -9.8, 0.1
t = 0
t_list, y_list = [], [] # Our "Data Buckets"

# 2. The Engine
while y > 0:
    t_list.append(t)
    y_list.append(y)
    
    v = v + (g * dt)
    y = y + (v * dt)
    t = t + dt

# 3. The Result
plt.plot(t_list, y_list)
plt.title("Free Fall Simulation")
plt.show()

LLM Interaction: Adding the Air Resistance Curve

Students will now ask the AI to modify this visualization to include drag.

The Guided Prompt:

"I have a Python loop that plots a falling object. Modify it to include air resistance.

  1. Add a drag force proportional to the velocity.

  2. Plot two lines on the same graph: one for 'Vacuum' (no air) and one for 'Air Resistance'.

  3. Use a legend to distinguish the two lines."

Lab Task: Identifying Terminal Velocity

  • The Challenge: Students must change the y-axis from Position to Velocity.

  • Visual Discovery: When they plot v_list, they will see the line "flatten out" into a horizontal line.

  • The Architect's Question: "At what time does the object stop accelerating? Find that point on your graph."

How to structure your "Virtual Lab"

  1. Initialize: Create empty lists for t and y.

  2. Simulate: Use a while loop to update physics.

  3. Capture: Use .append() inside the loop.

  4. Visualize: Call plt.plot() outside the loop.

Lab Task 1: The Vacuum vs. Air 🛠️

  1. Run the provided code that includes air resistance.

  2. Observe the curve: Is it still a perfect parabola? (Hint: No, it becomes linear!)

  3. The Challenge: Change the air density variable. How does the "bend" in the graph change?

Prompting for Velocity Graphs 🤖

Prompt Template:

"Modify my falling object script to plot Velocity vs. Time instead of Position.

  1. Make sure the velocity starts at 0.

  2. Show the horizontal line where the object reaches terminal velocity.

  3. Add a grid so I can read the exact terminal speed."

The "Terminal Velocity" Aha! Moment

Look at your new Velocity graph.

  • Why does the line stop going down and stay flat?

  • Physics Check: This is where . Gravity and Air Resistance are perfectly balanced.

Teaching Tool: Use this graph to show students that "acceleration stops" even though the object is still "moving fast."

Homework: The Parachute Jump

Task: Create a simulation where an object falls for 5 seconds, then the "drag" suddenly increases (the parachute opens).

  1. The Graph: Plot the velocity.

  2. The Goal: Show a sharp "drop" in velocity followed by a new, much slower terminal velocity.

Next Week (The Final Project)

"Next week is your turn. You will choose a topic—maybe planetary orbits, or a car braking, or a spring oscillating—and you will build a Google Colab 'Virtual Lab' that a high school student could use. You are no longer just learning Python; you are building the next generation of physics tools."

"Last week, we watched numbers scroll down our screen like the green code in _The Matrix_. It was exciting, but it’s hard to see a 'trend' in a list of numbers. Today, we are going to learn how to capture every single one of those 'ticks' and turn them into a visual curve. This is the moment where our simulation becomes a professional-grade scientific model."

"Before we can graph, we need a place to store our results. In Python, we create an empty list—think of it as an empty bucket. Every time the loop runs one 'tick' of time, we use a command called `.append()`. This literally means 'add to the end.' So, as the object falls, our bucket fills up with height measurements. By the time the loop finishes, we have a perfect history of the entire trip ready to be plotted."

"There is a specific order to this. First, you set the stage (initial conditions). Second, you start your 'clock' (the while loop). Third—and this is the new part—you save your data _inside_ the loop. Finally, only after the object has hit the ground and the loop is over, you tell the 'Graphing Factory' to draw the result. If you try to plot inside the loop, the computer will try to draw 100 separate graphs and crash! Always plot _after_ the simulation."

"I’ve given you a script that calculates two things at once: a ball in a vacuum and a ball in the air. When you run this, I want you to look at the shape of the lines. The vacuum line is a perfect parabola. But look at the air resistance line—it eventually becomes a straight diagonal. As a physics teacher, how would you explain that change to a student? That transition from a curve to a line is the 'signature' of air resistance."

"Position graphs are great, but velocity graphs tell the real story of forces. I want you to instruct your AI to switch the Y-axis to velocity. Look for the moment the line goes flat. That is your evidence. In a textbook, we tell students 'acceleration is zero at terminal velocity.' Here, they can actually see the slope of the graph become zero while the object is still moving."

"Look at your screen. Why did the line stop curving and go flat? In this digital lab, you can 'touch' the physics. If you increase the air density, that flat line moves up. If you make the object heavier, it moves down. This is the 'Aha!' moment where a student realizes that terminal velocity isn't a fixed number—it’s a balance of forces that they can manipulate with code."

"Your homework is a classic physics problem. A skydiver falls, reaches terminal velocity, and then opens a parachute. This means halfway through your loop, the 'drag' variable needs to jump up. Your graph should show a sharp change. If you can code this, you can simulate almost any complex motion in the high school curriculum."