Your grandparents have an annuity. The value of the annuity increases each month by an automatic deposit of 1% interest on the previous month’s balance.Your grandparents withdraw $1000 at the beginning of each month for living expenses. Currently, they have $50,000 in the annuity. Model the annuity with a dynamical system. Will the annuity run out of money? When? Hint: What value will have when the annuity is depleted?
As per on page 6
=50,000
Initial value is $50,000 Now after first month it will be $50,000 (initial value) + $500 ( 1% interest) -$1000 ( withdrawal)=$49500=
amountLeft=50000 #Initial amount
month=0 #initially 0th month
while(amountLeft >0)
{
month=month+1
amountLeft=1.01 * amountLeft-1000
cat(sprintf("Amount left: %f after %d month \n", amountLeft, month))
}
## Amount left: 49500.000000 after 1 month
## Amount left: 48995.000000 after 2 month
## Amount left: 48484.950000 after 3 month
## Amount left: 47969.799500 after 4 month
## Amount left: 47449.497495 after 5 month
## Amount left: 46923.992470 after 6 month
## Amount left: 46393.232395 after 7 month
## Amount left: 45857.164719 after 8 month
## Amount left: 45315.736366 after 9 month
## Amount left: 44768.893729 after 10 month
## Amount left: 44216.582667 after 11 month
## Amount left: 43658.748493 after 12 month
## Amount left: 43095.335978 after 13 month
## Amount left: 42526.289338 after 14 month
## Amount left: 41951.552232 after 15 month
## Amount left: 41371.067754 after 16 month
## Amount left: 40784.778431 after 17 month
## Amount left: 40192.626216 after 18 month
## Amount left: 39594.552478 after 19 month
## Amount left: 38990.498003 after 20 month
## Amount left: 38380.402983 after 21 month
## Amount left: 37764.207012 after 22 month
## Amount left: 37141.849083 after 23 month
## Amount left: 36513.267573 after 24 month
## Amount left: 35878.400249 after 25 month
## Amount left: 35237.184252 after 26 month
## Amount left: 34589.556094 after 27 month
## Amount left: 33935.451655 after 28 month
## Amount left: 33274.806172 after 29 month
## Amount left: 32607.554233 after 30 month
## Amount left: 31933.629776 after 31 month
## Amount left: 31252.966073 after 32 month
## Amount left: 30565.495734 after 33 month
## Amount left: 29871.150692 after 34 month
## Amount left: 29169.862198 after 35 month
## Amount left: 28461.560820 after 36 month
## Amount left: 27746.176429 after 37 month
## Amount left: 27023.638193 after 38 month
## Amount left: 26293.874575 after 39 month
## Amount left: 25556.813321 after 40 month
## Amount left: 24812.381454 after 41 month
## Amount left: 24060.505268 after 42 month
## Amount left: 23301.110321 after 43 month
## Amount left: 22534.121424 after 44 month
## Amount left: 21759.462638 after 45 month
## Amount left: 20977.057265 after 46 month
## Amount left: 20186.827838 after 47 month
## Amount left: 19388.696116 after 48 month
## Amount left: 18582.583077 after 49 month
## Amount left: 17768.408908 after 50 month
## Amount left: 16946.092997 after 51 month
## Amount left: 16115.553927 after 52 month
## Amount left: 15276.709466 after 53 month
## Amount left: 14429.476561 after 54 month
## Amount left: 13573.771326 after 55 month
## Amount left: 12709.509040 after 56 month
## Amount left: 11836.604130 after 57 month
## Amount left: 10954.970171 after 58 month
## Amount left: 10064.519873 after 59 month
## Amount left: 9165.165072 after 60 month
## Amount left: 8256.816723 after 61 month
## Amount left: 7339.384890 after 62 month
## Amount left: 6412.778739 after 63 month
## Amount left: 5476.906526 after 64 month
## Amount left: 4531.675591 after 65 month
## Amount left: 3576.992347 after 66 month
## Amount left: 2612.762271 after 67 month
## Amount left: 1638.889893 after 68 month
## Amount left: 655.278792 after 69 month
## Amount left: -338.168420 after 70 month
The data in the accompanying table show the speed n (in increments of 5 mph) of an automobile and the associated distance an in feet required to stop it once the brakes are applied. For instance, n=6 (representing 6 x 5 = 30 mph) requires a stopping distance of =47ft.
brakesDataFrame <- data.frame(n=1:16, an=c(3,6,11,21,32,47,65,87,112,140,171,204,241,282,325,376))
brakesDataFrame$deltaAn = c(NA,tail(brakesDataFrame$an,-1)-head(brakesDataFrame$an,-1))
brakesDataFrame
## n an deltaAn
## 1 1 3 NA
## 2 2 6 3
## 3 3 11 5
## 4 4 21 10
## 5 5 32 11
## 6 6 47 15
## 7 7 65 18
## 8 8 87 22
## 9 9 112 25
## 10 10 140 28
## 11 11 171 31
## 12 12 204 33
## 13 13 241 37
## 14 14 282 41
## 15 15 325 43
## 16 16 376 51
library(ggplot2)
ggplot(brakesDataFrame, aes(x=n, y=deltaAn)) +geom_line()
This is almost linear relationship.
we can assume that if n=0, stopping distance will be 0, that is line passes through origin.
To approximate the slope of this line calculating \(\frac{\Delta a_n}{n}\)
brakesDataFrame$slope <- brakesDataFrame$deltaAn / brakesDataFrame$n
slope <- mean(brakesDataFrame$slope, na.rm=TRUE)
slope
## [1] 2.57753
Plotting errors in the predicted values vs n
brakesDataFrame$estimate <- slope*brakesDataFrame$n # as per page 3
brakesDataFrame$error <- brakesDataFrame$estimate - brakesDataFrame$deltaAn
ggplot(brakesDataFrame, aes(x=n, y=error)) + geom_point()
## Warning: Removed 1 rows containing missing values (geom_point).
Looks like there is pattern to the errors. This model may not be appropriate.
Consider the spreading of a rumor through a company of 1000 employees, all working in the same building. We assume that the spreading of a rumor is similar to the spreading of a contagious disease (example 3, section 1.2) in that the number of people hearing the rumor each day is proportional to the product of the number who have heard the rumor previously and the number who have not heard the rumor. This is given by:
\[ r_{n+1} = r_n + kr_n (1000 - n) \]
Where \(k\) is a parameter that depends on how fast the rumor spreads and \(n\) is the number of days. Assume \(k = 0.001\) and further assume that four people initially have heard the rumor. How soon will all 1000 employees have heard the rumor?
\(n\) is the number of days assume that four people initially have heard the rumor
rumorDataFrame <- data.frame(n=0, r=4)
k <- 0.001
for(i in 1:13)
{
# as per given equation
tempvar<-c(i, rumorDataFrame$r[i] + k*rumorDataFrame$r[i]*(1000 - rumorDataFrame$r[i]))
rumorDataFrame <- rbind(rumorDataFrame,tempvar )
}
rumorDataFrame
## n r
## 1 0 4.00000
## 2 1 7.98400
## 3 2 15.90426
## 4 3 31.55557
## 5 4 62.11538
## 6 5 120.37244
## 7 6 226.25535
## 8 7 401.31922
## 9 8 641.58132
## 10 9 871.53605
## 11 10 983.49701
## 12 11 999.72765
## 13 12 999.99993
## 14 13 1000.00000
We can say,after 12 days, the rumor will have spread throughout the office.
An economist is interested in the variation of the price of a single product. It is observed that a high price for the product in the market attracts more suppliers. However, increasing the quantity of the product supplied tends to drive the price down. Over time, there is an interaction between price and supply. The economist has proposed the following model,p where \(P_n\) represents the price of the product at year \(n\), and \(Q_n\) represents the quantity. Find the equilibrium values for this system.
\[ P_{n+1} = P_n - 0.1(Q_n - 500) \] \[ Q_{n+1} = Q_n + 0.2(P_n - 100) \]
Yes it looks OK intuitively as it simpliefies things :)
100 and 500 looks equilibrium values. For that
If we put values
sign looks the negative and positive price-quantity relationship.
Test the initial conditions in the following table and predict the long-term behavior:
| Case | Price | Quantity |
|---|---|---|
| Case A | 100 | 500 |
| Case B | 200 | 500 |
| Case C | 100 | 600 |
| Case D | 100 | 400 |
library(reshape2)
years <- 50
pinit <- 100
qinit <- 500
economistDataFrame <- data.frame(n = 0, p = pinit, q= qinit)
for(i in 1:years){
economistDataFrame <- rbind(economistDataFrame,
c(i, tail(economistDataFrame$p,1) - 0.1*(tail(economistDataFrame$q,1) - 500),
tail(economistDataFrame$q,1) + 0.2*(tail(economistDataFrame$p,1) - 100)))
}
ggplot(melt(economistDataFrame, id="n"), aes(x=n, y=value, color=variable)) + geom_line()
#-------------------------------------------------------
pinit <- 200
qinit <- 500
economistDataFrame <- data.frame(n = 0, p = pinit, q= qinit)
for(i in 1:years){
economistDataFrame <- rbind(economistDataFrame,
c(i, tail(economistDataFrame$p,1) - 0.1*(tail(economistDataFrame$q,1) - 500),
tail(economistDataFrame$q,1) + 0.2*(tail(economistDataFrame$p,1) - 100)))
}
ggplot(melt(economistDataFrame, id="n"), aes(x=n, y=value, color=variable)) + geom_line()
#-------------------------------------------------------
pinit <- 100
qinit <- 600
economistDataFrame <- data.frame(n = 0, p = pinit, q= qinit)
for(i in 1:years){
economistDataFrame <- rbind(economistDataFrame,
c(i, tail(economistDataFrame$p,1) - 0.1*(tail(economistDataFrame$q,1) - 500),
tail(economistDataFrame$q,1) + 0.2*(tail(economistDataFrame$p,1) - 100)))
}
ggplot(melt(economistDataFrame, id="n"), aes(x=n, y=value, color=variable)) + geom_line()
#-------------------------------------------------------
pinit <- 100
qinit <- 400
economistDataFrame <- data.frame(n = 0, p = pinit, q= qinit)
for(i in 1:years){
economistDataFrame <- rbind(economistDataFrame,
c(i, tail(economistDataFrame$p,1) - 0.1*(tail(economistDataFrame$q,1) - 500),
tail(economistDataFrame$q,1) + 0.2*(tail(economistDataFrame$p,1) - 100)))
}
ggplot(melt(economistDataFrame, id="n"), aes(x=n, y=value, color=variable)) + geom_line()
I do not think this is good equation to indicate relationship. If we change quality and price by half then graph doesn’t keep relationship and goes mad.
pinit <- 50
qinit <- 200
economistDataFrame <- data.frame(n = 0, p = pinit, q= qinit)
for(i in 1:years){
economistDataFrame <- rbind(economistDataFrame,
c(i, tail(economistDataFrame$p,1) - 0.1*(tail(economistDataFrame$q,1) - 500),
tail(economistDataFrame$q,1) + 0.2*(tail(economistDataFrame$p,1) - 100)))
}
ggplot(melt(economistDataFrame, id="n"), aes(x=n, y=value, color=variable)) + geom_line()