Showing posts with label SM exercises. Show all posts
Showing posts with label SM exercises. Show all posts

Tuesday, September 27, 2011

Exercise 2.3 - Wizzles and Woozles

This is exercise 3.3 from the text, which is 2.2 online, and 2.3 in my nomenclature.

1. Consider a population of wizzles, which unlike woozles can multiply only when their numbers are larger than a certain minimal value a. If there are less byukies than a, they cannot find a partner for mating and the population dies off. The carrying capacity of the island where wizzles live is also A. Obviously A > a. What model would describe the population dynamics of wizzles on this island?

2. What are the equilibria in the byukies model? Are they stable? 
The solution that comes to mind isn't very satisfying, but it works. I've added an IF statement to the growth rate, such that if the A > a, the growth rate is positive, and if A < a, the growth rate is negative. The first image shows the model still works when the Ao > a; the second image shows the stable equilibrium at zero if the Ao < a.

Exercise 2.2 - Modeling a Toilet

A note on my nomenclature: This is exercise 3.2 from the text; it also happens to be 3.2 online, but online it's part of the art of modeling chapter, and in the text it's part of the math chapter. Following the online order, I'm calling the math chapter ch. 2, but since I'm working from the text for the math chapter (and only the math chapter) I'm calling this ex. 2.2. Whatever.

The model, as I downloaded it, needed to be broken before it could be fixed. First, I deleted the "/dt" from the outflow equation. Second, I changed the flush's if statement to be "if Use>0.995..." because I wasn't getting many flushes with the 0.999 threshold. Third, I deleted the seed from the random function ["RANDOM(0,1,14)" -> "RANDOM(0,1)"] in the parameter "use" to get different random flushings on each run. Doing that gives the following with dt = 0.5:



Q: Can you reformulate the model in such a way that the stock would be drained out properly under any computational method and any time step DT? As you may have noticed, when we switch to other methods, the outflow starts to deplete the stock, but then, apparently, does not have enough time to take it all out. How can this be fixed?

To get the tank to empty no matter what the dt, I just cranked up the outflow. Since tank is defined as a non-negative reservoir, this has no consequences. I made the outflow 1000 x tank, which should work up to a dt of 0.001. The result is:



Math! Simluation Modeling Exercises 2.1

1. Consider a population [in] which cells divide into 3 every time step. What mathematical model will describe this population? 
x(n) = 3x(n - 1)
= 3[3x(n-2)]
= 3{3[3x(n - 3)]} ...
= a3^n
2. Formulate the model with triple growth in terms of a differential equation and solve it. Is the difference between the discrete and continuous models larger or smaller than in the double growth model?
 x(t + dt) = x(t) + 2x(t)dt
[x(t + dt) - x(t)] / dt = 2x(t)
dx/dt = 2x
dx/x = 2dt ... Integrating gives:
ln x = 2t + C
x(t) = ae^(2t)

Now that we have the continuous and discrete models (ie., continuously compounded vs. compounded once per "t"), I plugged the equations into Excel to see how different they are. And they're hugely different! And the difference is much greater for the tripling equations: there's a million-fold difference between the two computation methods by the 16th generation!


time 2x discrete 2x cont. 3x discrete 3x cont. 2x ratio 3x ratio
1 2.00E+00 2.72E+00 3.00E+00 7.39E+00 1.36E+00 2.46E+00
2 4.00E+00 7.39E+00 9.00E+00 5.46E+01 1.85E+00 6.07E+00
3 8.00E+00 2.01E+01 2.70E+01 4.03E+02 2.51E+00 1.49E+01
4 1.60E+01 5.46E+01 8.10E+01 2.98E+03 3.41E+00 3.68E+01
5 3.20E+01 1.48E+02 2.43E+02 2.20E+04 4.64E+00 9.06E+01
6 6.40E+01 4.03E+02 7.29E+02 1.63E+05 6.30E+00 2.23E+02
7 1.28E+02 1.10E+03 2.19E+03 1.20E+06 8.57E+00 5.50E+02
8 2.56E+02 2.98E+03 6.56E+03 8.89E+06 1.16E+01 1.35E+03
9 5.12E+02 8.10E+03 1.97E+04 6.57E+07 1.58E+01 3.34E+03
10 1.02E+03 2.20E+04 5.90E+04 4.85E+08 2.15E+01 8.22E+03
11 2.05E+03 5.99E+04 1.77E+05 3.58E+09 2.92E+01 2.02E+04
12 4.10E+03 1.63E+05 5.31E+05 2.65E+10 3.97E+01 4.98E+04
13 8.19E+03 4.42E+05 1.59E+06 1.96E+11 5.40E+01 1.23E+05
14 1.64E+04 1.20E+06 4.78E+06 1.45E+12 7.34E+01 3.02E+05
15 3.28E+04 3.27E+06 1.43E+07 1.07E+13 9.98E+01 7.45E+05
16 6.55E+04 8.89E+06 4.30E+07 7.90E+13 1.36E+02 1.83E+06
17 1.31E+05 2.42E+07 1.29E+08 5.83E+14 1.84E+02 4.52E+06
18 2.62E+05 6.57E+07 3.87E+08 4.31E+15 2.50E+02 1.11E+07
19 5.24E+05 1.78E+08 1.16E+09 3.19E+16 3.40E+02 2.74E+07
20 1.05E+06 4.85E+08 3.49E+09 2.35E+17 4.63E+02 6.75E+07


3. Suppose you have $10,000 on your savings bank account with an annual interest rate of 3%. Build a model to calculate your interest earnings in 5 years. What will be the difference in your earnings if the interest is calculated monthly instead of annually? How much does the bank make on your account by calculating the interest monthly, instead of doing it continuously?

Continuous interest accumulates by the formula:
A = Ao x e^(rt)
Where A is the final amount, Ao is the initial amount, r is the interest rate, and t is time elapsed.

So after five years:
A5 = $10,000 x e^(0.03 x 5) = $11,618.34
If the interest is compounded in discrete steps, the operative formula is:

  (thanks, Wikipedia!)
where n is the number of compounding periods per year, in this case 12, so:
A5 = $10,000 x (1 + 0.03/12)^(12 x 5) = $11,616.17
So the bank pockets $2.17 every five years by compounding interest monthly rather than continuously.

Is this discrepancy so much smaller than for the doubling and tripling functions because of the low interest rate? If, instead of a savings account, this were a delinquent credit account that accumulated interest at 28%, after five years, the $10k would be:
Monthly compounding: $39.904.99
Continuous compounding: $40,552.00
Indeed, the difference after five years at 28% (~$550) is about 5% of the initial amount, where the difference after five years at 3% (~$2) is about 0.02% of the initial amount. Since these are exponential functions, as more time elapses, the difference will become more pronounced, as it did in the doubling and tripling exercises.

So the take home message from these exercises seems to be: the greater the rate of change, the more important the time increment.

Monday, September 26, 2011

Simulation Modeling Exercises 3.1

Finally got Stella installed! $129 for a perpetual student license. A good deal, but no upgrades, and they're set to upgrade in a few months. Did a quick tutorial from Voinov's online course, now on to the first exercises that actually involve playing with models. Yippie!

1. A model of a car dealership. The number of customers is random and sales occur with a certain probability. New stock is delivered with a delay. At given model parameters the stock goes to zero at certain times. How to avoid this if:
a) the delivery time is no less than 10 days?
b) or the size of the warehouse is limited by 100 units?
c) or both of the above? Can you change the dealership operation in such a way, that the average number of units sold daily will be above 10, while the stock size will be maintained below 50?



Stock (blue) and # deals/day (red) using either
a moving average or 10, whichever is greater.
This took a long time (and dinged my modeling confidence, but hey, I'm a beginner, right?), but I found something that works. I made two changes to the number of deliveries: to smooth things out, I use a moving average of the past 10 days (which is 10 to 20 days ago when the cars get delivered). In addition to using the moving average, I also set a minimum number of deliveries for each day of 10. That way, if the dealership had a bad day 10 days ago, we still get 10 cars 10 days later, so the inventory never collapses.

2. A simple population growth model, that has a certain growth rate and mortality rate. At this time it shows exponential growth with the population increasing to infinity. Modify the model in such a way that the population would grow to 400 and stabilize at about that size. Can this be achieved by changing parameter values only or the functions that describe flows need be modified? 
Booyah! #2 came much easier and more elegantly, if I may say so myself. All I did was modify the birthrate to be a function of the ratio of the population to the target population relative to the death rate. So my birthrate equation became
(Target_Population/Population)*Death_Rate
and the model and output ended up looking like this. Notice that now we can stabilize the population at whatever target we want.
3. The system describes a human population, which growth also depends upon the level of "development". The larger the population, the higher level of development it can reach. The development in turn stimulates population growth. As development grows, more babies are born, therefore the higher the population. Is there anything wrong with this conceptual model? What modifications could make the system "sustainable"? (That is, keep both variables within certain limits, avoiding extinction and runaway growth to infinity)

One way this model differs from the real world is that natality is linearly influenced by development, while in the real world, natality is inversely influenced by development; that is, as development increases, family size goes down. Making just that one change to the model, stabilizes the population at 30 and development at 1.5.

4. A model of CO2 and biomass on this planet. CO2 is released into the atmosphere. It is consumed by the forests. The forests are cut at a certain rate. They also decompose adding to the pool of CO2. Currently the model displays infinite growth of forests. How to modify the system to stabilize it?
Deforestation = Biomass / 100
I suspect there are many ways to stabilize this system, and I'd rather have done this by adjusting photosynthesis rate so that it's not linearly affected by CO2 (it's not, and in the climate change debate, that matters. If we assume, as Dr. Voinov seems to here, that as we pump more CO2 into the atmosphere, forests will be proportionally stimulated, then we'd have much less to be concerned with than we do). Nevertheless, one easy solution is to make the deforestation rate proportional to the amount of forest. Since the deforestation was originally set to 1 and biomass to 100, I used deforestation = biomass/100 to keep the initial deforestation rate the same, and the simulation stabilizes nicely.

5. Model of body weight. You gain weight because you eat. You loose weight due to exercising. However the more you exercise, the higher your appetite. Also the more you weigh the higher the appetite. So the weight grows and grows. Can this pattern be changed? 

Well, I suppose it's as good a time as any to show how ridiculous an exercise modeling can be if you're not careful. I solved this one analytical and managed to stabilize the weight right at 120 ... with -48.5 hours of exercise a day! Hmm... back to the drawing board.

There's another solution, which I also hit on analytically, which stabilizes weight with a positive value for exercise. All I did was set the equations for food intake and weight loss equal, decided that calorie content and exercise efficiency should be static parameters (so I substituted the values from the original model), and then solved for exercise in terms of body weight, which ends up being body weight * .07/2.3, and the model ends up looking like that to the left.

6. A river is represented by 5 identical reaches. The water collected from the catchment area drains into the river reach N5 and then travels down the river. The precipitation pattern is random and results in sharp oscillations in the river stage in the reaches. What changes to parameters and/or functions are necessary to stabilize the system so that
1) there is no accumulation of water in the river;
2) the oscillations in the water depth are smoothed out.
Modify the model to describe the travel of one pulse of water through the river system. 

I don't completely understand this model. I don't get what the parameter M is. However, by unclogging the plug at the bottom of the model, I accomplished the two goals. I increased the outflow rate from 0.1 to 1, which drains the system so that water no longer accumulates, but doesn't drain it so fast that the each precipitation event flashes through all five reaches.

Fun with modeling! I really love this stuff and am glad to have moved from the theoretical part of the course to the hands on part. Can't wait until we're building our own models. First, "Essential Math."

Thursday, September 8, 2011

Simulation Modeling Exercises Module 1


Exercise 1.1

Can you think of 3 other examples of models? What is the spatial/ temporal resolution in your models?

1. An engineer’s diagram of a circuit board. Spatial resolution is on the order of microns, no temporal resolution.

2. An architect’s blueprint. Spatial resolution is on the order of cm, no temporal resolution.

3. A timeline of the history of an invasion. Spatial resolution is on the order of km, temporal resolution on the order of months.
Model of Napoleon’s ill-fated 1812 invasion of Russia. Thickness of the line represents troop numbers, brown on the advance, black on the retreat. Troop size, location, date, and temperature are all captured in the model. Edward Tufte called this “probably the best statistical graphic ever drawn.”
Can you use an electric lamp as a model of the sun? What goals could such a model meet?

You could use a lamp as a model of the sun to show how light radiates out from a sphere. If your goal were to demonstrate how eclipses are generated by different states of the sun-earth-moon system, this would make an excellent model.

Exercise 1.2

Think of examples of 3 systems. How would you describe these systems?

The human body is a complex system made up of scores of organs, each of which with unique and interacting functions. An organ is a system composed of one or more types of cellular tissue. Cells within tissue interact to produce a function such as nutrient absorption or hormone secretion. Cells are complex systems comprised of proteins, membranes, and genetic material, each of which could again be described as a system.

Describe chicken noodle soup as a system. What are the elements? What is the function? What makes it a system?

Chicken noodle soup could be thought of a system comprised of water, soluble chicken elements, chicken meat, noodles, and spices. My functions for chicken soup are warmth, nourishment, and feelings of comfort, but the function of chicken soup for a chicken may be quite different, and the function for, say, Lipton, different still. It can be thought of as a system because it has multiple components which, when combined, produce a function greater than the sum of its parts. I would not derive the same satisfaction as from eating  a bowl of chicken soup by eating a chicken, drinking a glass of water, swallowing a bunch of garlic and black pepper, and then sitting on the stove for an hour.

Exercise 1.3

List five elements for each of the following systems:

I.        steam engine
1.       Fuel
2.       Combustion chamber
3.       Boiler
4.       Water pump
5.       Water

II.      oak tree
1.       Roots
2.       Xylem
3.       Phloem
4.       Leaves
5.       Acorns

III.    Thanksgiving turkey
1.       Skin
2.       Flesh
3.       Bones
4.       Gravy
5.       Stuffing

IV.    city
1.       Roads
2.       Buildings
3.       Public officials
4.       Merchants
5.       Sewers

What is the system that has the following elements: water, gravel, 3 fish, fish feed, aquatic plants?

One such system is an aquarium.

What if we add a scuba diver to this list? Can elements entirely describe a system?

Then it’s either an ecologically poor lake or sea or a very large aquarium with a scuba diver that needs a new hobby.

Elements cannot describe a system completely for at least two reasons; one is that we have defined a system as having emergent properties that are greater than the sum of its components, and another is that we cannot ever fully describe the elements of a system; there is always another level of detail to which we could appeal (eg., human body, organs, tissues, cells, proteins, atoms, quarks, strings…).

Exercise 1.4

Look at a tree in a forest and describe the relevant hierarchy.

The immediate super-system of the tree is the forest ecosystem, composed of a population of that species of tree, a community of trees and other plants, a collection of animals, fungi, etc.. Moving further up the hierarchy, the forest ecosystem fits within the global ecosystem. In the other direction, the tree’s organs—leaves, xylem, roots, etc.—are subsystems of the tree. Each of those contain tissues and within those cells, proteins, atoms, etc..

Think of an example when a system is affected by a system 3 levels above in the hierarchy, but is not affected by the system 2 levels above in the hierarchy. Is this possible?

I am going to assume that the question intends the meaning “is not being affected by the system 2 levels above in the hierarchy at the moment” because, by definition, a system can be affected by any super-system. With that caveat, using Alexi’s example of a student as a system and the class as the immediate supersystem, the department could be a system 2 levels up, and the university a system 3 levels up. If the university instituted new degree requirements, that could affect the student directly, while the interaction between the student and the department remained the same.

If a system collapses (dies off) can subsystems survive?

Sure. When an animal dies, the proteins within them survive for a time. They will eventually decay, but the sub-er-system of atoms will ultimately survive.