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
URGENT: Federal Reserve Announces MASSIVE Rate Cut, Bailout Begins!
What’s up you guys? It’s Graham here, and I hope you’re prepared for what just happened. As of a few hours ago, for the first time since March of 2020, the Federal Reserve has finally made the decision to lower interest rates after one of the most aggress…
Khan Academy Ed Talk with Mike Flanagan
Hello and welcome to Ed Talks with Khan Academy. I’m Kristin Disarro, the Chief Learning Officer at Khan Academy, and I am excited today to talk to Mike Flanagan, the CEO of the Mastery Transcript Consortium. We’ll find out what that is and what it means …
Conclusion for a two-sample t test using a P-value | AP Statistics | Khan Academy
A sociologist studying fertility in France and Switzerland wanted to test if there was a difference in the average number of babies women in each country have. The sociologists obtained a random sample of women from each country. Here are the results of t…
My Tenant Just Trashed My House | The Aftermath
What’s up, you guys? It’s Graham here. So, this is certainly not a video that I wanted to make, but as somebody who’s been in the real estate industry for 14 years, it’s only a matter of time until eventually you come across a situation like this. So, I’…
Is the 2024 Gold Rush a Warning to the US Economy?
Have a look at this price chart over the last 2 years. Up 65% phenomenal growth! Now, with returns like that, you’d probably expect it to be some sort of up-and-coming tech stock, right? One with a foot in the door of the artificial intelligence Gold Min…
Those “Real Estate Investor Seeks Trainee” Signs: Make $120k/yr With No Experience?!
What’s up you guys? It’s Graham here. So, after posting a video the other week explaining the truth behind the “We Buy Houses Fast Cash” signs, a new question kept coming up and that was, what about the real estate investors’ “Sheiks Trainee” signs? After…