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
Cameras Reveal the Secret Lives of a Mountain Lion Family | Short Film Showcase
Mountain lion, puma, cougar— all names for an animal that has long been misunderstood, feared, hunted, and eliminated from most of its range. The cougar is often believed to be solitary and even heartless, but recently, deep in the Wyoming Wind River Rang…
Zeros of polynomials (with factoring): grouping | Polynomial graphs | Algebra 2 | Khan Academy
So we’re told that p of x is equal to this expression here, and it says plot all the zeros or x intercepts of the polynomial in the interactive graph. The reason why it says interactive graph is this is a screenshot from this type of exercise on Khan Acad…
How I make $13,800 PER MONTH on YouTube (How much YouTubers make)
So I definitely don’t want to give anyone the idea that the only reason I’m doing this is for money because that couldn’t be further from the truth, and I would be doing this regardless of how much money I make. But I have a feeling this video might inspi…
How to Throw an Atlatl | Live Free or Die: DIY
[Music] So this is the ATL, and this is what they call the dart. It predates the bow and arrow people. It’s really responsible for our survival as human beings. So this tool has been used for a longer duration than probably any other hunting tool that ma…
The 5 Things Successful People Do In Their 20’s
What’s up you guys? It’s Graham here. So your 20s are really such an important time. I honestly believe that it’s these early years that best form the foundation for everything else you do later in life. Much like it’s the easiest to learn a second langua…
A day in my life in Japan vlog-Shopping/Getting a haircut
[Music] Okay, so good morning! It’s currently 4:35 AM, and I just woke up. You might think, “Why are you waking up this early?” The reason is, yesterday I was so tired, so I just went to bed pretty early, at 7:30 PM or something, so that I can wake up tod…