Introductions

About the Course

Why Simulation?

Why Statistics?

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.

Course Syllabus

We'll take a few minutes to talk about how the course is structured before we proceed to today's material.

What is Simulation?

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.

What it isn't

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.

Simulation in General

Based on two ideas:

First Models

Easy, Boring Problems

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).

txv
0760
16760
212760
318760

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).

tyva
010000-10
11000-10-10
2990-20-10
3970-30-10
4940-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

Interesting Problems

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

Simple Interest

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.

  • Usually, the interest rate is quoted as an annual rate. Therefore, the amount of interest in dollars is:
    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?

    Compound Interest

    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

    Monthinterestbalance
    Jan1.0000101.0000
    Feb1.0100102.0100
    Mar1.0201103.0301
    Apr1.0303104.0604
    ...
    Dec1.1157112.6825
    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.

    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 =

    Extend Simulation

    We'll be using professional simulation software called Extend to run our simulations. You'll find it on the Macs.

    How to Start Extend

    Extend is not currently on the Mac dock. It's as easy to add it as to launch it, so let's do that:

    1. Click on the desktop or the Finder icon on the dock so that you're talking to the Finder. There should be a "Go" menu at the top. Or use the folder to the left of the Trash can.
    2. Under "Go," choose "Applications."
    3. Find the folder called "Extend 6" and within it, find the application called "Extend 6.0.4". The icon looks like this:
      Extend icon
    4. Drag that application to the dock. The other icons will move around to make room for it. (You probably shouldn't modify the dock on random public computers, though.)
    5. Close the Finder window(s)

    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.

    Interest

    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.

    Lake Pollution

    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:

    Cedar Bog

    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)

    Star Logo

    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.

    Recap

    Simulation is based on allowing the computer to play out the effects of many state changes. We specify

    and let the computer do the rest.

    Examples of state:

    Anything that may change over the course of the simulation and is either causal (affects the state) or interesting (we want to measure) is part of the 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 | Creative Commons License | Viewable With Any
Browser | Valid HTML 4.01! | Valid CSS!