Matt Moramarco
12/21/15
Roulette — In American roulette, there are 38 spaces on the wheel: 0, 00, and 1–36. Half the spaces numbered 1–36 are red and half are black. The two spaces 0 and 00 are green.
Simulate the playing of 1000 games betting either red or black (which pay even money, 1:1). Bet $1 on each game and keep track of your earnings. What are the earnings per game betting red/black according to your simulation? What was your longest winning streak? Your longest losing streak?
The expected value of this bet is \( 1 \cdot \frac{18}{38} + (-1) \cdot \frac{20}{38}=-0.5263168 \).
samples_space <- c(rep("red",18),rep("black",18),rep("green",2))
roulette <- function(x) {
win_streak <- 0; lose_streak <- 0
max_win_streak <- 0; max_lose_streak <- 0
earnings <- 0
for (i in 1:x) {
result <- sample(samples_space,1)
if (result == "black") {
win_streak <- win_streak + 1
earnings <- earnings + 1
if (max_win_streak < win_streak) {
max_win_streak <- win_streak
}
lose_streak <- 0
} else {
lose_streak <- lose_streak + 1
earnings <- earnings - 1
if (max_lose_streak < lose_streak) {
max_lose_streak <- lose_streak
}
win_streak <- 0
}
}
return(rbind(earnings,max_win_streak,max_lose_streak))
}
set.seed(4127)
roulette(1000)
[,1]
earnings -52
max_win_streak 9
max_lose_streak 14
Simulate 1000 games betting green (pays 17:1, so if you win, you add $17 to your kitty, and if you lose, you lose $1). What are your earnings per game betting green according to your simulation? How does it differ from your earnings betting red/black? What was your longest winning streak betting green? Longest losing streak? Which strategy do you recommend using, and why?
The expected value of this bet is \( 17 \cdot \frac{2}{38} + (-1) \cdot \frac{36}{38}=-0.5263168 \).
[,1]
earnings -190
max_win_streak 1
max_lose_streak 100
A farmer has 30 acres on which to grow tomatoes and corn. Each 100 bushels of tomatoes require 1000 gallons of water and 5 acres of land. Each 100 bushels of corn require 6000 gallons of water and 2.5 acres of land. Labor costs are $1 per bushel for both corn and tomatoes. The farmer has available 30,000 gallons of water and $750 in capital. He knows that he cannot sell more than 500 bushels of tomatoes or 475 bushels of corn. He estimates a profit of $2 on each bushel of tomatoes and $3 on each bushel of corn.
a. How many bushels of each should he raise to maximize profits?
Our maximization function is \( z=2x+3y \) where \( x \) is the number of bushels of tomatoes and \( y \) is the number of bushels of corn, subject to the following constraints:
\( 10x+60y \leq 30000 \),
\( 0.05x+0.025y \leq 30 \),
\( x+y \leq 750 \),
\( x \leq 500 \),
\( y \leq 475 \)
This provides the following vertices: \( (0,475),(150,475),(300,450),(450,300),(500,200) \). Using our maximization equation with the above vertices, we get: \( 1425, 1725, 1950, 1800, 1600 \) respectively. Therefore, our maximum profits are at \( (300,450) \).
Write a computer code to perform the gradient method of steepest ascent algorithm using the multiplier technique \( \lambda_{k+1}=\epsilon \lambda_k \) discussed in this section. Use your code to solve Problems 1, 5, 6, and 7 of this section.
gradient <- function(f, px, py, x_zero=0, y_zero=0, lambda=1/16, epsilon=1.2, iterations=30) {
x <- rep(x_zero,iterations)
y <- rep(y_zero,iterations)
f_results <- rep(0,iterations)
px_results <- rep(0,iterations)
py_results <- rep(0,iterations)
lambda_k <- rep(lambda,iterations)
delta <- rep(0,iterations)
f_results[1] <- f(x[1],y[1])
px_results[1] <- px(x[1],y[1])
py_results[1] <- py(x[1],y[1])
delta <- f_results[1]
for (i in 2:iterations) {
x[i] <- x[i-1]+lambda_k[i-1]*px_results[i-1]
y[i] <- y[i-1]+lambda_k[i-1]*py_results[i-1]
f_results[i] <- f(x[i],y[i])
px_results[i] <- px(x[i],y[i])
py_results[i] <- py(x[i],y[i])
lambda_k[i] <- lambda_k[i-1]*epsilon
delta[i] <- f_results[i] - f_results[i-1]
}
return(cbind(x,y,f_results,delta,lambda_k))
}
Find the local maximum value of the function \( f(x,y)=xy-x^2-y^2-2x-2y+4 \).
x y f_results delta lambda_k
[23,] -1.999988 -1.999988 8 -1.011546e-10 3.450384
[24,] -2.000029 -2.000029 8 -7.073506e-10 4.140461
[25,] -1.999909 -1.999909 8 -7.521573e-09 4.968553
The local maximum is 8.
A company manufactures \( x \) floor lamps and \( y \) table lamps each day. The profit in dollars for the manufacture and sale of these lamps is \( P(x,y)=18x+2y-0.05x^2-0.03y^2+0.02xy-100 \). Find the daily production level of each lamp to maximize the company's profits.
x y f_results delta lambda_k
[38,] 200.0221 99.99147 1800.000 -2.829188e-05 53.16014
[39,] 199.8955 100.04219 1799.999 -6.572996e-04 63.79217
[40,] 200.6160 99.74736 1799.976 -2.331296e-02 76.55060
The maximum profit is 1,800.