yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Simulations and repetition | Intro to CS - Python | Khan Academy


2m read
·Nov 10, 2024

I'm running a coin flip experiment and I want to find out how likely each outcome is: heads or tails. So I flip a coin once, twice, 100 times. Once I've repeated that experiment enough times, I see that about 50% of my flips are heads and 50% are tails.

Now, that's not a particularly interesting result. You probably could have told me that's what would happen at the beginning. But what if the experiment I want to repeat is much bigger? Instead of physically performing the experiment, we can simulate it with code.

For example, maybe I want to simulate a car crash to predict the risk of injury to the passengers, or I want to simulate a forest fire to predict how far it'll spread, or I want to simulate crop growth so I can predict yields and decide what to plant. These are all things that would be far too costly, too devastating, or take far too long to repeat in the real world.

But if we build a computer simulation, we can repeat the experiment as many times as we want for free, modifying different data inputs along the way. To simulate crop growth, I might combine climate and soil data with different irrigation and fertilizer choices, and then repeat how that affects my crop growth over a series of time steps.

Weather simulations work the same way. They collect wind, air pressure, and other readings from hundreds of different balloons, buoys, and satellites, and apply mathematical models over a series of time steps.

Okay, but why is the weather forecast wrong so much of the time then? It's almost impossible to 100% model the real world in a program. There's just so much data and randomness to take into account. And as humans, we don't always have access to all the data or 100% understand all the relationships involved.

Sometimes there are simply too many relationships that the computer physically can't process that much information in a reasonable amount of time. These are some of the limitations of our current weather models. We don't have data on the conditions at every single point on Earth, and even if we did, the computer wouldn't be able to handle all that data.

We can, in theory, more accurately predict tomorrow's weather, but by the time we get the result, it'll be the day after tomorrow. So for practicality, almost all simulations make some assumptions or simplifications about the world around us and settle for good enough results according to their needs.

Whether there's constraints on the data available, the amount of time they have to build the simulation, or the sheer computing power required, with just conditionals and variables, we can start to write our own basic simulations in Python. We're only missing two things: we need to be able to repeat our experiment and we need to be able to model some of the randomness that occurs in the real world.

More Articles

View All
Mechanical waves and light | Waves | Middle school physics | Khan Academy
Let’s talk about waves. So, let’s imagine that you were to take a string and attach it at one end to a wall, and then on the other end, you were to wiggle it up and down. Well, then you would have made a wave. You would see a pattern that looks like this.…
Science and Comedy - Perfect Together | StarTalk
Star Talk would not be Star Talk were it not for the tandem comedic elements that we weave into the science that we are otherwise conveying. What you will notice from Seth McFarlane, if you only catch the highlights of his comedic life, you may only have …
Revolutionizing the Way We Grow Food | Nat Geo Live
( intro music ) Caleb Harper: My talk is about how to solve the global food crisis. Technology and seed is for an adverse world. What if you had a perfect world? Researching this, for me, took me to a place of learning about Mir Space Station. You know, …
My Thoughts On The Millionaire Tax
What’s up, Graham? It’s Guys here. So, I want to talk about something that I’ve seen come up a lot lately, and that would be a proposed wealth tax. Now, initially, this is not a topic I was planning to address, but because we talk all things personal fina…
Finding function from power series by integrating | Series | AP Calculus BC | Khan Academy
We know that for (x) in the open interval from (-\frac{1}{2}) to (\frac{1}{2}), that (-\frac{2}{1-2x}) is equal to this series, and I say using this fact, find the function that corresponds to the following series. And like always, pause this video and se…
Citizenship in the US territories and District of Columbia | High school civics | Khan Academy
[Presenter] Did you know that there are more than 4 million people who live in American territories that aren’t part of the 50 US states? In fact, the US claims 16 territories outside of the continental United States, although a few of those are in disput…