Вы находитесь на странице: 1из 11

ISDA 609: Homework 1

Solutions

Sunday, February 21, 2016

Page 8: #10

10. Your grandparents have an annuity. The value of the annuity increases each month by an automatic
deposit of 1% interest on the previous months 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
an have when the annuity is depleted?

Giordano, Frank R.; Fox, William P.; Horton, Steven B. (2013-02-14). A First Course in Mathematical
Modeling (Page 8). Cengage Textbook. Kindle Edition.
Dynamical system model:
an+1 = an + 0.01 an 1000,
a0 = 50000

# Starting value
annuity = c(50000)

# Numerical system model


while(annuity[length(annuity)] > 0){
current.value <- annuity[length(annuity)]
next.value <- current.value + 0.01*current.value - 1000
annuity <- c(annuity, next.value)
}

# x axis
month = 0:(length(annuity) - 1)

# plot
plot(month, annuity)
abline(h=0, col="red")

1
50000
30000
annuity

10000
0

0 10 20 30 40 50 60 70

month

The annuity will run out of money in month 69.

Page 17: #9

9. 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 a6 = 47f t.

n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

an 3 6 11 21 32 47 65 87 112 140 171 204 241 282 325 376

Giordano, Frank R.; Fox, William P.; Horton, Steven B. (2013-02-14). A First Course in Mathematical
Modeling (Page 17). Cengage Textbook. Kindle Edition.

a. Calculate and plot the change an versus n. Does the graph reasonably approximate a linear relation-
ship?

# Enter information. n is speed in 5 mph increments


# a_n is stopping distance in feet
n <- 1:15
braking.distance <- c(3, 6, 11, 21, 32, 47, 65, 87, 112, 140, 171, 204, 241, 282, 325, 376)

2
# initialize differences vector
delta <- numeric()

# compute differences
for(i in n){
diff <- braking.distance[i+1] - braking.distance[i]
delta <- c(delta, diff)
}

# fit a linear model


lm1 <- lm(delta ~ n)

#plot
plot(n, delta,
xlab = "n", ylab = "delta a[n]",
main = "delta a[n] vs n")
abline(lm1, col="blue")

delta a[n] vs n
50
40
delta a[n]

30
20
10

2 4 6 8 10 12 14

Visually you can see that the graph reasonably approximates a linear relationship.

b. Based on your conclusions in part (a), find a difference equation model for the stop- ping distance data.
Test your model by plotting the errors in the predicted values against n. Discuss the appropriateness of
the model.

The difference equation model:

3
Based on the relationship established in part a:
an+1 an = k n + C, where k = 3.25 and C = 1.1 So the difference equation model is:
an+1 = 3.25 n + an + (1.1)
Generating values with this model and calculating the errors at each point we have:

a0 = 0
k = lm1$coefficients[2]
intercept = lm1$coefficients[1]

predicted.dist = k * 1 + a0 + intercept

# generate numerical solution


for(i in 1:15){
predicted.dist[i+1] <- predicted.dist[i] + k * i + intercept
}

# plot errors
plot(predicted.dist - braking.distance)
predicted.dist braking.distance

2
1
0
1
2

5 10 15

Index

# compare predicted vs actual braking distance


plot(braking.distance)
points(predicted.dist, pch=19, col="red")

4
300
braking.distance

200
100
0

5 10 15

Index

From an intuitive perspective this model makes sense. It is acurately capturing the growth. It corresponds
quite well to the data we have. It is reasonable to assume that as speed continues to increase, the stopping
distance will also continue to increase in this manner, i.e. unlike the examples, there would not be a limit to
the the stopping distance. On the low end, we would expect the braking distance to be 0 when your speed is
zero. This model has a slight error there, but introducing that error leads to much better agreement with the
other data.

Page 34: #13

13. 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
(see 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
rn+1 = rn + k rn (1000 rn )
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?

Giordano, Frank R.; Fox, William P.; Horton, Steven B. (2013-02-14). A First Course in Mathematical
Modeling (Page 34). Cengage Textbook. Kindle Edition.

# create numerical model from given equation


k <- 0.001
r <- 4

5
while(r[length(r)] < 1000){
r[length(r) + 1] <- r[length(r)] + k * r[length(r)]*(1000 - r[length(r)])
# print(c(r[length(r)], k, (1000 - length(r))))
}

day <- 0:(length(r) - 1)

plot(day, r)
abline(h=999, col="red")
1000
800
600
r

400
200
0

0 2 4 6 8 10 12 14

day

By the 11th day, all employees will have heard the rumor.

Page 55: #6

6. An economist is interested in the variation of the price of a single product. It is ob- served 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, where Pn represents the price of the product
at year n, and Qn represents the quantity. Find the equilibrium values for this system.

Pn+1 = Pn 0.1(Qn 500)

Qn+1 = Qn + 0.2(Pn 100)

a. Does the model make sense intuitively? What is the significance of the constants 100 and 500? Explain
the significance of the signs of the constants -0.1 and 0.2.

6
b. Test the initial conditions in the following table and predict the long-term behavior.

Price Quantity

Case A 100 500


Case B 200 500
Case C 100 600
Case D 100 400

Giordano, Frank R.; Fox, William P.; Horton, Steven B. (2013-02-14). A First Course in Mathematical
Modeling (Page 55). Cengage Textbook. Kindle Edition.
For equilibrium, Pn+1 = Pn = P and Qn+1 = Qn = Q so we have:
P = P 0.1(Q 500)
Q = Q + 0.2(P 100)
or
0.1(Q 500) = 0 Q = 500
0.2(P 100) P = 100

(a) Does the model make sense intuitively? What is the significance of the constants 100 and 500? Explain
the significance of the signs of the constants -0.1 and 0.2.

The model make sense in that it captures the relationship proposed by the economist. The 100 and 500 set
the equilibrium values for price and quantity and the -0.1 and 0.2 determine how strongly or quickly the
model reacts to changes away from those quantities. From the first equation, there is downward pressure on
price when the quantity is above 500 and upward pressure on price when quantity is below 500 (that is the
significance of the sign of -0.1). From the second equation this is reversed due to the difference in the sign of
0.2. When the price is above 100, there is upward pressure on quantity and when the price is below 100 there
is downward pressure on quantity.

(b) Testing initial conditions:

time.steps <- 1:200


#Initial conditions
P <- 100
Q <- 400

simulation <- function(time.steps, P, Q){


response.p <- P
response.q <- Q
for(step in time.steps){
response.p[step + 1] <- response.p[step] - 0.1*(response.q[step] - 500)
response.q[step+1] <- response.q[step] + 0.2*(response.p[step] - 100)
}
return(list(response.p, response.q))
}

x <- c(0, time.steps)

7
# Plot parameters
y.limits <- c(-400, 1000)

In the following graphs, price is shown in red and quantity is shown in blue:

# Case A
response.A <- simulation(time.steps, 100, 500)

plot(x, response.A[[1]], type="b", ylim=y.limits, col="red", main="Case A")


points(x, response.A[[2]], type="b", pch=19, col="blue")
abline(h=100, col="red")
abline(h=500, col="blue")

Case A
1000
600
response.A[[1]]

0 200
400

0 50 100 150 200

# Case B
response.B <- simulation(time.steps, 200, 500)

plot(x, response.B[[1]], type="b", ylim=y.limits, col="red", main="Case B")


points(x, response.B[[2]], type="b", pch=19, col="blue")
abline(h=100, col="red")
abline(h=500, col="blue")

8
Case B
1000
600
response.B[[1]]

0 200
400

0 50 100 150 200

# Case C
response.C <- simulation(time.steps, 100, 600)

plot(x, response.C[[1]], type="b", ylim=y.limits, col="red", main="Case C")


points(x, response.C[[2]], type="b", pch=19, col="blue")
abline(h=100, col="red")
abline(h=500, col="blue")

9
Case C
1000
600
response.C[[1]]

0 200
400

0 50 100 150 200

# Case D
response.D <- simulation(time.steps, 100, 400)

plot(x, response.D[[1]], type="b", ylim=y.limits, col="red", main="Case D")


points(x, response.D[[2]], type="b", pch=19, col="blue")
abline(h=100, col="red")
abline(h=500, col="blue")

10
Case D
1000
600
response.D[[1]]

0 200
400

0 50 100 150 200

In all cases except when the system starts at the equilibrium values, the system is unstable and price and
quantity exhibit a continuously increasing oscillatory pattern as described in part (a). The oscilations are 90
degrees out of phase, which makes sense. Obviously, this model falls apart when it starts predicting negative
prices and quantities. Something should be added to establish upper and lower bounds on price and a lower
bound on quantity.

11

Вам также может понравиться