Here's an example: Global Rich List. Last time I checked, the ranking function didn't work, but the data still does.
Nevertheless, Statistics can be hard. The logic takes some getting used to and the calculations can be opaque. Be patient with yourselves. Bring questions to class and office hours, post questions, and practice.
We'll take a few minutes to talk about how the course is structured before we proceed to today's material.
It's a model that we can compute with. It's necessarily incomplete, an approximation. In short, everything we do here is a falsehood. Nevertheless, it's useful.
It's not animation. We will often have nice graphics, but that is icing on the cake. It's not what simulation is primarily about. We will, however, think about ways to present numerical information in an intuitive way.
Based on two ideas:
constant speed problems: Suppose your initial state is being at mile marker 7 and moving at 60 mph. Each hour, your state changes by 60 miles. (Each minute, your state changes by 1 mile).
t x v 0 7 60 1 67 60 2 127 60 3 187 60
constant acceleration problems: Suppose your initial state is being 1000 meters above the earth, moving at zero meters per second. Each second, your velocity increases by 10 meters per second (negative, because you're moving downward).
t y v a 0 1000 0 -10 1 1000 -10 -10 2 990 -20 -10 3 970 -30 -10 4 940 -40 -10 5 6 7 8
The rule here, is that each state variable changes in a predictable way based on the current state. To be specific:
yt+1 = yt + vt
vt+1 = vt + at
Please control-click on this and save it to your desktop (Firefox: control-click, then "save link as"; Safari: control-click then "download linked file"; Netscape: Save Link Target As, IE: download link target to disk). Double-click it to open it. If it doesn't open in Excel, launch Excel and open it by hand.
An Excel Spreadsheet with some examples
Some amount of money, called the principal is borrowed for some time, call the term. After the loan is up, the principal is repaid, with an extra amount called interest.
I = P * r * t
Example: You borrow $100 for 1 year at 5% interest. After one year, you have to pay back the original $100, plus 100*0.05*1 = 5, or $105 total.
Example: You borrow $100 for 2 years at 10% interest. After the term, you pay back the principal, plus 100*0.1*2 = 20, or $120 total.
Experiment with the simple interest worksheet. Try the examples. Make sure you feel comfortable with the answers you're getting.
Copy values to additional columns so that you can compare amounts.
Q: Would you rather borrow $100 for 5 years at 3% or 3 years at 5%?
A: What do you think?
Like simple interest, compound interest has a principal, an (annual) interest rate, a term, and a resulting interest. The difference is that interest is calculated at regular intervals (called the compounding period) and accrues: the interest is added to the balance as an additional amount to be repaid. Most things use compound interest: bank accounts, mutual funds, mortgages, car loans, student loans.
In other words, you're paying interest on the old, unpaid, interest as well as on the principal.
Mathematically, we are repeating the simple interest calculation each period.
Calculating this is much harder. Good thing we have computers!
Example: We borrow $100 for 2 years at 10%, compounded yearly. How much interest do we pay?
After the first year, we calculate interest of 100*0.1*1 or 10 dollars. Now our balance is 110 dollars. It's as if we are borrowing 110 dollars for one (more) year at 10%. So, after the second year, we calculate interest of 110*0.1*1 or 11 dollars. So, we pay 10 dollars of interest the first year and 11 dollars the second, for a total of $21. We have to pay back $121 total. Contrast this with the simple (non-compounding) interest.
Most compounding periods are less than a year. Bank accounts often compound monthly or daily, or even continuously. Let's look at an example of monthly compounding.
Since interest rates are usually quoted per annum rather than per period, you have to divide the interest rate by the number of periods per year to determine the periodic rate. For example, at 12 percent annual rate, compounded monthly, is 1 percent per month.
Example: We deposit $100 in a bank account that earns 12% per year, compounded monthly. What is our balance at the end of the year?
At the end of January, they deposit 100*0.12/12 or 1 dollar
At the end of February, they deposit 101*0.12/12 or 1.01 dollars
At the end of March, they deposit 101.01*0.12/12 or 1.0101 dollars
At the end of the year, we have a balance of $112.68, so we earned $12.68 in interest. Only 68 cents better than simple interest! Also, notice that the bank has to do its calculations to hundredths of a penny just to notice much difference. Still, if that were a million dollars instead of a hundred, it would make a difference.
Month interest balance Jan 1.0000 101.0000 Feb 1.0100 102.0100 Mar 1.0201 103.0301 Apr 1.0303 104.0604 ... Dec 1.1157 112.6825
Play with Excel. Select the "Compound" worksheet. The first column in the tabular part is the period number, which is just the month. Each line has the old balance (the balance at the beginning of the period), the interest calculation, and the new balance (just the old balance plus the interest).
What are the equations for this model?
interestt+1 =
balancet+1 =
We'll be using professional simulation software called Extend to run our simulations. You'll find it on the Macs.
Extend is not currently on the Mac dock. It's as easy to add it as to launch it, so let's do that:
Now, click on the Extend icon on the dock to launch Extend. We may have to do this every week or so as the machines get refreshed.
Our first example is, for the sake of continuity, another look at compound interest. Download the following to your desktop and then open it with Extend (File/Open or command-O). Don't double-click on it; that won't work.
Interest Model (Extend Model)
This is a model of yearly compounding, with a constant controlling the initial deposit and the interest rate. The central icon is an "accumulator:" it represents our balance. Notice the $1000 going in as well as the product of the interest rate and the current amount. We'll learn more about this next time.
If you then run the model (Apple-r or Run > Run Simulation ), you'll automatically get a graph of the results. Notice the huge balance after 30 years: $17,449. Not too bad.
Next, download the following to your desktop and open it with Extend. Better, since it's a built-in demo, you can open it under
Extend 6 / Examples / Tutorials / Lake Pollution.mox
Here's the model for your desktop, if you prefer to do it that way.
Lake Pollution (Extend Model)
Ignore the details for now. We'll learn more as the semester progresses.
In this simulation, there are two industrial plants built on the shore of a pristine lake and they begin polluting the lake. One plant produces a large amount of pollution and exactly the same amount of pollution each year; the other produces a smaller amount, but highly variable. The lake gets fresh water from rain and from upstream and loses polluted water downstream. After 20 years, the first plant closes.
When we run the model, we can see both the inflow of pollution (red line) and the total pollution in the lake (blue line). We'll run this together and try to understand the graph a little.
Hints:
If we have time, we'll run this demo, too. Again, it's built-in as
Extend 6 / Examples / Continuous Processes / Science & Engineering / Standard Block Models / Cedar Bog Lake.mox
Here's the actual model file:
Cedar Bog (Extend Model)
We'll also be using some simulation/animation software called StarLogo. You'll find it on the Macs under "Applications." Open it and then open the demo called "rabbits":
File > Open Project > Mac HD > Applications > StarLogo > Sample Projects > Biology > rabbits.slogo
This simulates an "ecosystem" consisting of grass and rabbits that eat it. If there's enough grass, the rabbits make babies. If there's not enough, they die.
The green patches are grass. The rabbits are strange-looking gray icons.
Run this demo by clicking on the blue "Go" button. You can see how the grass is consumed and the rabbits multiply by looking at the graphs.
Simulation is based on allowing the computer to play out the effects of many state changes. We specify
Examples of state:
For now, we are doing continuous simulation, which is also known as process simulation. This is used for systems where things change "smoothly" as a result of the passage of time. This is most often the case with processes in scientific fields such as chemistry and physics, but also in many other fields.
The time intervals of the simulation can be important. If you're familiar with calculus, the preceding ideas in continuous simulation are essentially the concepts underlying integration, but true integration requires an infinitesimal time step (that is, the integral is the limit as the time step shrinks to zero). In practical simulations, we can't have a time step of zero, but if we're willing to spend a lot of time, we can get quite close.
Parting words
This work is licensed under a Creative Commons
License |
|
|
|