Linear Algebra

System of Equation

You keep a number of lizards, mice and peacocks as pets. There are a total of 108 legs and 30 tails in your menagerie. You have twice as many mice as lizards. How many of each creature do you have?

Lizards and mice each have 4 legs and peacocks have 2

\[ 4l + 4m + 2p = 108 \]

Each pet has one tail

\[ l + m + p = 30 \]

Since there are twice as many mice than lizards

\[ 2l - m = 0 \]

Create Matrix

pets = matrix( c(4,1,2,4,1,-1,2,1,0,108,30,0), nrow=3, ncol=4)
pets
##      [,1] [,2] [,3] [,4]
## [1,]    4    4    2  108
## [2,]    1    1    1   30
## [3,]    2   -1    0    0

Solve Matrix

#Multiply Row 2 by a factor of 4 in order to solve for p
pets [1,] - 4*(pets [2,])
## [1]   0   0  -2 -12

Since \(-2p = -12\), there are 6 peacocks. We can substitute this value into either Row 1 or 2 and then use Row 3 to solve a 2 by 2 system of equation. I used Row 2 to substitute p=6.

pets2 = matrix( c(1,2,1,-1,24,0), nrow=2, ncol=3)
pets2
##      [,1] [,2] [,3]
## [1,]    1    1   24
## [2,]    2   -1    0
#Add the two rows in order to solve for l
pets2 [1,] + pets2 [2,]
## [1]  3  0 24

Since \(3l = 24\), there are 8 lizards. We can now conclude that there are 16 mice since the problem stated there are twice as many mice than lizards.

Final Answer: 16 mice, 8 lizards, 6 peacocks

Vector Space

Calculate the dot product u.v where u = [0.5;0.5] and v = [3;-4]

\[ u \cdot v = u_1*v_1 + u_2*v_2 \] Use dot function from geometry package

# Formula: u . v = u1v1 + u2v2
# u . v = 1.5 - 2 = -0.5
library (geometry)
u = c(0.5, 0.5)
v = c(3,-4)
dotprod = dot (u,v,d = NULL)
dotprod
## [1] -0.5

What are the lengths of u and v?

\[ \sqrt ({u_1}^2 + {u_2}^2) \]

#sqrt (u . u)
u_length = sqrt (0.5^(2)+0.5^(2))
#sqrt (v . v)
v_length = sqrt (3^(2)+ (-4)^(2))

u_length
## [1] 0.7071068
v_length
## [1] 5

What is the angle between u and v?

\[ cos(\theta) = \frac{u\cdot v } {|u| |v|} \]

# Formula: cos (theta) = (u-v) / (||u|| . ||v||)
radians = acos ( (dotprod) / (crossprod(u_length, v_length)) )
degrees = radians * 180 / pi
degrees
##         [,1]
## [1,] 98.1301

Eigenvalues

I will use the following formula: \[ \begin{aligned} \ det( a-\lambda * I) = 0 \end{aligned} \]

# Create the matrix a
a <-matrix(c(1,2,3,0,4,5,0,0,6),3,3,byrow=TRUE)
a
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0    4    5
## [3,]    0    0    6
#identity matrix
i <-matrix(c(1,0,0,0,1,0,0,0,1),3,3,byrow=TRUE)
i 
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1

\[ \begin{aligned} \ (1-\lambda )(4-\lambda )(6-\lambda) + (2)(5)(0) + (3)(0(0) -(3)(4-\lambda)(0) - (1-\lambda)(5)(0) - (2)(0)(6-\lambda)= 0 \end{aligned} \]

Eigenvalues based on the below lambda = 1,4,6

\[ \begin{aligned} \ (1-\lambda )(4-\lambda )(6-\lambda) = 0 \end{aligned} \]

# Use 'eigen' function
 
eigenvalues <- eigen(a)
eigenvalues
## eigen() decomposition
## $values
## [1] 6 4 1
## 
## $vectors
##           [,1]      [,2] [,3]
## [1,] 0.5108407 0.5547002    1
## [2,] 0.7981886 0.8320503    0
## [3,] 0.3192754 0.0000000    0

Characteristic Polynomial

\[ \begin{aligned} \ -\lambda^3 + 11\lambda^2 -34\lambda +24 = 0 \end{aligned} \]

charpoly function from the pracma package provides the characteristic polynomial.

# Use 'charpoly' function for the characteristic polynomial
 
library (pracma)
cp <- charpoly(a)
cp
## [1]   1 -11  34 -24

Eigenvectors

# Plug in 1 to get eigenvector
lambda1 <-matrix(c(0,2,3,0,3,5,0,0,5),3,3,byrow=TRUE)
lambda1
##      [,1] [,2] [,3]
## [1,]    0    2    3
## [2,]    0    3    5
## [3,]    0    0    5
rref (lambda1)
##      [,1] [,2] [,3]
## [1,]    0    1    0
## [2,]    0    0    1
## [3,]    0    0    0
# Plug in 4 to get eigenvector
lambda4 <-matrix(c(-3,2,3,0,0,5,0,0,2),3,3,byrow=TRUE)
lambda4
##      [,1] [,2] [,3]
## [1,]   -3    2    3
## [2,]    0    0    5
## [3,]    0    0    2
rref (lambda4)
##      [,1]       [,2] [,3]
## [1,]    1 -0.6666667    0
## [2,]    0  0.0000000    1
## [3,]    0  0.0000000    0
# Plug in 6 to get eigenvector
lambda6 <-matrix(c(-5,2,3,0,-2,5,0,0,0),3,3,byrow=TRUE)
lambda6
##      [,1] [,2] [,3]
## [1,]   -5    2    3
## [2,]    0   -2    5
## [3,]    0    0    0
rref (lambda6)
##      [,1] [,2] [,3]
## [1,]    1    0 -1.6
## [2,]    0    1 -2.5
## [3,]    0    0  0.0

Eigenvectors for 1,4,6 respectively

##      [,1]
## [1,]    1
## [2,]    0
## [3,]    0
##      [,1]
## [1,]    2
## [2,]    3
## [3,]    0
##      [,1]
## [1,]   16
## [2,]   25
## [3,]   10

Probability

Simple Probability

A box contains 54 red marbles, 9 white marbles, and 75 blue marbles. If a marble is randomly selected from the box, what is the probability that it is red or blue?

red_or_blue <- 54 + 75
all_marbles <- 54 + 9 + 75
round (red_or_blue/all_marbles,4)
## [1] 0.9348

A bag contains 9 red, 4 orange, and 9 green jellybeans. What is the probability of reaching into the bag and randomly withdrawing 4 jellybeans such that the number of red ones is 0, the number of orange ones is 1, and the number of green ones is 3?

red <- 9
orange <- 4
green <- 9
#choose zero red beans
red_combinations <- (factorial(red)) / ((factorial(red-0)*factorial(0)))
#choose 1 orange bean
orange_combinations <- (factorial(orange)) / ((factorial(orange-1)*factorial(1)))
#choose 3 green beans
green_combinations <- (factorial(green)) / ((factorial(green-3)*factorial(3)))
#choose 4 out of 22 total beans
all_combinations <-  (factorial(22)) / ((factorial(22-4)*factorial(4)))
round((red_combinations * orange_combinations * green_combinations)/all_combinations,4)
## [1] 0.0459

You are going to play mini golf. A ball machine that contains 19 green golf balls, 20 red golf balls, 24 blue golf balls, and 17 yellow golf balls, randomly gives you your ball. What is the probability that you end up with a red golf ball?

red <- 20
all_balls <- 19 + 20 + 24 + 17
round (red/all_balls,4)
## [1] 0.25

A pizza delivery company classifies its customers by gender and location of residence. The research department has gathered data from a random sample of 1399 customers. The data is summarized in the table below.

What is the probability that a customer is not male or does not live with parents?

not_male <- 228+79+252+97+72
not_parents <- 81+116+130+129
# We are given in the problem there are 1399 customers
round ( (not_male+not_parents) / 1399, 4 )
## [1] 0.8463

Conditional Probability

In a poker hand, John has a very strong hand and bets 5 dollars. The probability that Mary has a better hand is .04. If Mary had a better hand she would raise with probability .9, but with a poorer hand she would only raise with probability .1. If Mary raises, what is the probability that she has a better hand than John does?

\[ P(A|B) = \frac{P(A \cap B)} {P(B)} \]

A = Mary has a better hand

B = Mary raises

Given: \[ P(A) = .04\] \[P(B|A) = .9\] \[P(B|A^c) = .1\] We can substitute into:

\[ P(A|B) = \frac{P(A) P (B|A)} {P(A)P(B|A)+P(A^c)P(B|A^c)} \] \[ P(A|B) = \frac {(.04)(.9)}{(.04)(.9)+(.96)(.1)} \]

\[ P(A|B) = \frac {(.04)(.9)}{(.04)(.9)+(.96)(.1)} * \frac{1000}{1000} = \frac{36}{132} = \frac{3}{11}\]

## [1] 0.2727273

Permutation & Combination

Evaluate the following expression. \[ \frac{11!} {7!} \]

factorials <- 11*10*9*8
factorials
## [1] 7920

A veggie wrap at City Subs is composed of 3 different vegetables and 3 different condiments wrapped up in a tortilla. If there are 8 vegetables, 7 condiments, and 3 types of tortilla available, how many different veggie wraps can be made?

vegetables <- 8
condiments <- 7
tortilla <- 3
vegetables_combinations <- (factorial(vegetables)) / ((factorial(vegetables-3)*factorial(3)))
condiments_combinations <- (factorial(condiments)) / ((factorial(condiments-3)*factorial(3)))
tortilla_combinations <- (factorial(tortilla)) / ((factorial(tortilla-1)*factorial(1)))
vegetables_combinations * condiments_combinations * tortilla_combinations
## [1] 5880

The newly elected president needs to decide the remaining 8 spots available in the cabinet he/she is appointing. If there are 14 eligible candidates for these positions (where rank matters), how many different ways can the members of the cabinet be appointed?

positions <- 8
candidates <- 14
factorial (candidates) / factorial (candidates-positions)
## [1] 121080960

Law of Large Numbers

A fair coin is tossed 100 times. The expected number of heads is 50, and the standard deviation for the number of heads is \((100 * 1/2 * 1/2)^{1/2} = 5\) . What does Chebyshev’s Inequality tell you about the probability that the number of heads that turn up deviates from the expected number 50 by three or more standard deviations (i.e., by at least 15)?

\[ P(|X-\mu| \ge k\sigma) \le \frac{\sigma^2} {k^2\sigma^2} = \frac{1} {k^2} \] Let X by any random variable with E (X) = \(\mu\) and V (X) = \(\sigma^2\)

Given:

\(\mu\) = 50

\(\sigma\) = 5

k = 3

(Based on the above formula and given values) for any random variable, the probability of a deviation from the mean of more than k standard deviations is \(\frac{1} {k^2}\)

\[ P(|X-50| \ge 15) \le \frac{5^2} {3^25^2} = \frac{1} {3^2} = \frac{1}{9} \]

Central Limit Theorem

A die is rolled 24 times. Use the Central Limit Theorem to estimate the probability that

A) the sum is greater than 84.

B) the sum is equal to 84.

\[ E(X) = (1*1/6) + (2*1/6) + (3*1/6) + (4*1/6) + (5*1/6) + (6*1/6) = \frac{7} {2} \] \[ V(X) = 1/6 *((1-7/2)^2 + (2-7/2)^2 + (3-7/2)^2 + (4-7/2)^2 + (5-7/2)^2 + (6-7/2)^2)\] \[ V(X) = 1/6 *((25/4) + (9/4) + (1/4) + (1/4) + (9/4) + (25/4))\] \[ V(X) = 1/6 *(70/4) = \frac{35}{12}\]

We need to address the “24” rolls:

\[ E(X) = 24 * \frac{7} {2} = 84 \] \[ V(X) = 24 * \frac{35} {12} = 70 \] \[ \sigma = \sqrt70 = 8.3666\] A) the sum is greater than 84.

\[ P (S_{24} > 84) = P(S_{24} > \frac {84.5-84}{8.3666})\]

x <- (84.5-84)/(8.3666)
probability_a <- 1-pnorm(x)
probability_a
## [1] 0.4761728

B) the sum is equal to 84.

\[ P (S_{24} = 84) = P(S_{24} > \frac {84.5-84}{8.3666}) - P(S_{24} > \frac {83.5-84}{8.3666}) \]

b <- (83.5-84)/(8.3666)
probability_b <- pnorm(b)
#we will use variable x from part a
probability_x <- pnorm (x)
probability_x - probability_b
## [1] 0.04765436

Markov Chain

Part 1

\[\mathbf{P^2} = \left[\begin{array} {rrr} 0.7 & 0.06 & 0.24 \\ 0.33 & 0.52 & 0.15 \\ 0.42 & 0.33 & 0.25 \end{array}\right] \]

Since the \(ij^{th}\) entry of the matrix \(P^n\) gives the probability that the Markov chain starting in state i will be in state j after n steps. Thus, the probability that the grandson of a man from Harvard went to Harvard is the upper-left element of the matrix

#given
pharvard = 0.8
pharvard_yale = 0.2
pyale_harvard = 0.3
pharvard_darmouth = 0
pdarmouth_harvard = 0.2
#formula
probability_grandson <- (pharvard)*(pharvard) + (pharvard_yale)*(pyale_harvard) +
  
(pharvard_darmouth)*(pdarmouth_harvard)
probability_grandson
## [1] 0.7

Part 2

#given for question 5
pharvard = 1
pharvard_yale = 0
pyale_harvard = 0.3
pharvard_darmouth = 0
pdarmouth_harvard = 0.2
#formula
prob_grandson <- (pharvard)*(pharvard) + (pharvard_yale)*(pyale_harvard) + 
(pharvard_darmouth)*(pdarmouth_harvard)
prob_grandson
## [1] 1

Smith is in jail and has 1 dollar; he can get out on bail if he has 8 dollars. A guard agrees to make a series of bets with him. If Smith bets A dollars, he wins A dollars with probability .4 and loses A dollars with probability .6.

Find the probability that he wins 8 dollars before losing all of his money if he bets 1 dollar each time (timid strategy).

I will use a for loop to calculate the probability if Smith chose the timid strategy.

# given probability Smith wins
wins = 0.4
# given probability Smith loses
loses = 0.6
#ratio of probabilities to use in loop
x = loses/wins
#the following loop will print out the probabilities for bets 1-7
for (i in seq(1,7,1))
{ 
  print ((1-x^i)/(1-x^8))
  }
## [1] 0.02030135
## [1] 0.05075337
## [1] 0.0964314
## [1] 0.1649485
## [1] 0.267724
## [1] 0.4218874
## [1] 0.6531324
timid <- 1 - ((x-(x^8))/(1-(x^8)))
timid
## [1] 0.02030135

Answer: The probability increases as Smith continues to win. The probability that he wins 8 dollars before losing all of his money with the timid strategy is the first component of the vector or 0.0203.

Find the probability that he wins 8 dollars before losing all of his money if he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy).

I will use the Absorbing Markov Chains concept illustrated in page 417 of the textbook to calculate the probability if Smith chose the bold strategy. It is also important to note that this Markov chain differs from the timid strategy because we are only interested in outputs of having 0,1,2,4,8 dollars. This is because a win will double the earnings and a loss will result in $0.

q <- matrix(c(rep(c(0,0.4,0,0),2),0), 3, byrow = 3)
q
##      [,1] [,2] [,3]
## [1,]    0  0.4  0.0
## [2,]    0  0.0  0.4
## [3,]    0  0.0  0.0
#create a 3 x 3 identity matrix
i <- diag (x=1, 3, 3)
i
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
#Use solve function to find fundamental matrix
s <- solve (i-q)
s
##      [,1] [,2] [,3]
## [1,]    1  0.4 0.16
## [2,]    0  1.0 0.40
## [3,]    0  0.0 1.00
#This matrix along with the above 's' will be used for the absorption 
#that I assigned the value 'bold' to below
r <- matrix(c(rep(c(0.6,0),2),0.6,0.4),3, byrow=TRUE)
r
##      [,1] [,2]
## [1,]  0.6  0.0
## [2,]  0.6  0.0
## [3,]  0.6  0.4
#Bold Strategy Results
bold <- s %*% r
bold
##       [,1]  [,2]
## [1,] 0.936 0.064
## [2,] 0.840 0.160
## [3,] 0.600 0.400
bold[1,2]
## [1] 0.064

Answer: The probability that Smith wins 8 dollars before losing all of his money with the bold strategy is 0.064.

Since this is a higher probability, Smith has a better chance of getting out of jail with the Bold Strategy.

Simulation of Discrete Probability

Tversky and his colleagues studied the records of 48 of the Philadelphia 76ers basketball games in the 1980-81 season to see if a player had times when he was hot and every shot went in, and other times when he was cold and barely able to hit the backboard. The players estimated that they were about 25 percent more likely to make a shot after a hit than after a miss. In fact, the opposite was true-the 76ers were 6 percent more likely to score after a miss than after a hit. Tversky reports that the number of hot and cold streaks was about what one would expect by purely random effects. Assuming that a player has a fifty-fifty chance of making a shot and makes 20 shots a game, estimate by simulation the proportion of the games in which the player will have a streak of 5 or more hits.

Shots Made + Streak Calculator

set.seed(824)

streak <- function(x){
  #get lengths
  y <- rle(x>0)
  lengths <- y$lengths
  values <- y$values
  
  
  largest_run <- which(lengths==max(lengths[values]) & values)
  return(max(lengths[largest_run]))
}
shots_made <- function(){
  # make 20 shots a game
  random_generator <- runif(20, min=0, max=1)
  # assign 0 for values under 0.5 and assign 1 for values over 0.5 
  # from runif() random generator function in above line 
  random_generator[random_generator < .5] <- 0
  random_generator[random_generator >= .5] <- 1
  #refer back to streak function
  result = streak(random_generator)
  return(result)
}

Step by Step on how function is converting randomly generated values and providing the largest streak as the output

random_generator<- runif(20, min=0, max=1)
#Original Values
random_generator
##  [1] 0.757482962 0.780467369 0.763638493 0.653780217 0.542056970 0.221782881
##  [7] 0.472220019 0.001218389 0.736160030 0.033215435 0.548479494 0.801811954
## [13] 0.472014646 0.896111947 0.746937350 0.775631770 0.983303579 0.833804163
## [19] 0.825391286 0.517226145
random_generator[random_generator < .5] <- 0
random_generator[random_generator >= .5] <- 1
#Converted Values
random_generator
##  [1] 1 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 1 1 1
#Longest Streak
result <- streak(random_generator)
result
## [1] 7

Simulation

streak_simulation <- function(n){
  i = 1
  j = 0
  while (i < n){
    simulate <- shots_made()
    i = i + 1
    #streak of 5 or more
    if (simulate >= 5){
      j <- j + 1
    }
  }
  return(j)
}

Run Simulations to see that the proportion of the games in which the player will have a streak of 5 or more hits is ~ 0.25

(streak_simulation (50)) /50
## [1] 0.22
(streak_simulation (100)) /100
## [1] 0.19
(streak_simulation (500)) /500
## [1] 0.21
(streak_simulation (1000)) /1000
## [1] 0.249
(streak_simulation (5000)) /5000
## [1] 0.2578
(streak_simulation (10000)) /10000
## [1] 0.2458
(streak_simulation (50000)) /50000
## [1] 0.25062
(streak_simulation (100000)) /100000
## [1] 0.24937

Probability Distributions

Let X1, X2, . . . , Xn be n mutually independent random variables, each of which is uniformly distributed on the integers from 1 to k. Let Y denote the minimum of the Xi’s. Find the distribution of Y.

In order to find the distribution function P(Y=s), we need to count how many ways we can assign the mutually independent random variables to values between s and k with at least one Xi being assigned to s. We would then divide this by the total number of possibilites of assigning the mutually independent random variables to values between 1 and k.

The total number of possibilities is \(k^n\) since each Xi has k possibilities (1,2,3….,k)

Y = 1 is a minimum possibility and is in the subset of the total \(k^n\). In order to calculate the number of ways that Y = 1, we need to subtract all cases where none of the Xi values are equal to 1 from the total \(k^n\). This gives us the following when Y = 1:

\(k^n - (k-1)^n\)

However, there is also a possibility that Y = 2. If this is the case, we need to subtract all cases where none of the Xi values are equal to 2 and the cases where Y = 1 since 2 is representing the minimum value. This gives us the following when Y = 2:

\(k^n - (k-2)^n - (k^n - (k-1)^n)\)

Simplify \((k-1)^n - (k-2)^n\)

I will now do the same for Y = 3 to illustrate the pattern:

\(k^n - (k-3)^n - ((k-1)^n - (k-2)^n) - (k^n - (k-1)^n)\)

Simplify \((k-2)^n - (k-3)^n\)

Referring back to if Y=s, we can confidently conclude that:

\[\frac{(k-s+1)^n - (k-s)^n} {k^n}\]


Your organization owns a copier (future lawyers, etc.) or MRI (future doctors).This machine has a manufacturer’s expected lifetime of 10 years. This means that we can expect one failure every ten years.

What is the probability that the machine will fail after 8 years? Provide also the expected value and standard deviation. Model as a geometric.

Geometric

Given p+q = 1

p = 0.1 since the probability of a machine failing once occurs every 10 years (1/10)

q = 0.9

\[P(X = x) = q^{x-1}*p\] \[P(X > 8) = 0.9^{8}\]

\[E(X) = \frac1p\] \[E(X) = \frac1{0.1}\]

\[Var(X) = \frac q{p^2}\] \[Var(X) = \frac{0.9}{0.1^2}\]

#not fail first 8 years
geo_prob <- pgeom (0,0.9^8)
geo_expected <- 1/0.1
geo_sd <- sqrt (0.9/0.1^(2))
print(paste("The probability that the machine will fail after 8 years is",
            round(geo_prob,4), ",the expected value is ", round(geo_expected,2), 
            "and the standard deviation is ", round(geo_sd,4))) 
## [1] "The probability that the machine will fail after 8 years is 0.4305 ,the expected value is  10 and the standard deviation is  9.4868"

What is the probability that the machine will fail after 8 years? Provide also the expected value and standard deviation. Model as an exponential.

Exponential

Given

m (decay parameter) = 0.1 since the probability of a machine failing once occurs every 10 years (1/10)

\[P(X \le x) = 1-e^{-mx}\] \[P(X > 8) = 1- (1-e^{-0.1*8})\] \[\mu = E(X) = \frac1m\]

\[E(X) = \frac1{0.1}\]

\[\sigma^2=Var(X) = \frac1{m^2}\]

\[\sigma^2=Var(X) = \frac1{0.1^2}\]

exp_prob <- exp(-0.1*8)
exp_expected <- 1/0.1
exp_sd <- sqrt (1/0.1^(2))
print(paste("The probability that the machine will fail after 8 years is"
            ,round(exp_prob,4), ",the expected value is ", round(exp_expected,2),
            "and the standard deviation is ", round(exp_sd,4))) 
## [1] "The probability that the machine will fail after 8 years is 0.4493 ,the expected value is  10 and the standard deviation is  10"

What is the probability that the machine will fail after 8 years? Provide also the expected value and standard deviation. Model as a binomial.

Binomial

Given n = 8

k = 0

p = 0.1 since the probability of a machine failing once occurs every 10 years (1/10)

\[ \binom{n}{k}=\frac{n!} {(n-k)!k!} \] \[ P(k|out|of|n|ways) = \binom{n}{k} *p^k * (1-p)^{n-k} \] \[ P(X>8) = \binom{8}{0} *0.1^0 * (1-0.1)^{8-0} \] \[\mu = E(X) = n*p\] \[\mu = E(X) = 8*0.1\] \[\sigma^2=Var(X) = n*p*(1-p)\]

\[\sigma^2=Var(X) = 8*0.1*(1-0.1)\]

binom_prob <- choose(8,0)*(1-0.1)^(8)
binom_expected <- 8*0.1
binom_sd <- sqrt (8*0.1*(1-0.1))
print(paste("The probability that the machine will fail after 8 years is",round(binom_prob,4),
            ",the expected value is ", round(binom_expected,2),
            "and the standard deviation is ", round(binom_sd,4))) 
## [1] "The probability that the machine will fail after 8 years is 0.4305 ,the expected value is  0.8 and the standard deviation is  0.8485"

Additional Binomial Distribution Examples

If you throw exactly three heads in four tosses of a coin you win $97. If not, you pay me $30.

Step 1 Find the expected value of the proposition.

# When you flip a coin four times, the total number of outcomes is as follow
total_outcomes <- 2^4
# zero heads
H0T4 <- (factorial(4)) / ((factorial(4-0)*factorial(0)))
# one head
H1T3 <- (factorial(4)) / ((factorial(4-1)*factorial(1)))
# two heads
H2T2 <- (factorial(4)) / ((factorial(4-2)*factorial(2)))
# three heads
H3T1 <- (factorial(4)) / ((factorial(4-3)*factorial(3)))
# four heads
H4T0 <- (factorial(4)) / ((factorial(4-4)*factorial(4)))
#calculating expected value. 0,1,2,4 heads are being multiplied by -30 
#for when a player loses $30. 3 heads is multiplied by 97 for when a player wins $97.
expected_value <- (H0T4*-30/total_outcomes) + (H1T3*-30/total_outcomes) +
  (H2T2*-30/total_outcomes) + (H3T1*97/total_outcomes) + (H4T0*-30/total_outcomes)
round (expected_value,2)
## [1] 1.75

Step 2 If you played this game 559 times how much would you expect to win or lose?

#if a player plays 559 times
559 * expected_value
## [1] 978.25

Flip a coin 9 times. If you get 4 tails or less, I will pay you $23. Otherwise you pay me $26.

Reference

Reference

Step 1 Find the expected value of the proposition.

Outcomes

\[ \binom{n}{k}=\frac{n!} {(n-k)!k!} \]

\[ \binom{9}{0}=\frac{9!} {(9-0)!0!} \]

\[ \binom{9}{1}=\frac{9!} {(9-1)!1!} \]

\[ \binom{9}{2}=\frac{9!} {(9-2)!2!} \]

\[ \binom{9}{3}=\frac{9!} {(9-3)!3!} \]

\[ \binom{9}{4}=\frac{9!} {(9-4)!4!} \]

Total Outcomes

\[ 2^9 = 512\]

n <- 9
k <- 4
 
#possible outcomes
number_of_tails <- (0:9)
#dbinom gives the probability of each outcome
all_probabilities <- dbinom (0:9, 9, 0.5)
 
#we notice symmetry from 0 to 4 tails compared to 5 to 9 tails
data.frame(number_of_tails, all_probabilities)
##    number_of_tails all_probabilities
## 1                0       0.001953125
## 2                1       0.017578125
## 3                2       0.070312500
## 4                3       0.164062500
## 5                4       0.246093750
## 6                5       0.246093750
## 7                6       0.164062500
## 8                7       0.070312500
## 9                8       0.017578125
## 10               9       0.001953125
#probability of 0,1,2,3,4 tails
x <- dbinom (0:4,9,0.5)
sum(x)
## [1] 0.5
#checking with pbinom that we have the same sum
pbinom(k,n,.5)
## [1] 0.5
#23 dollars for winning, 26 dollars lost for losing
expected_value2 <- (23)*(pbinom(k, n, .5)) + (-26)*(1-pbinom(k,n,.5))
print (paste("Expected Value:",round(expected_value2,2)))
## [1] "Expected Value: -1.5"

Step 2 If you played this game 994 times how much would you expect to win or lose?

#if a player plays 994 times
994 * expected_value2
## [1] -1491

What is the probability that the machine will fail after 8 years? Provide also the expected value and standard deviation. Model as a Poisson.

Poisson

Given \(\lambda\) = (0.1)*(8)

x = 0

\[ P(x;\lambda) = \frac{e^{-\lambda} * \lambda^x} {x!}\] \[ P(X > 8) = \frac{e^{-0.1*8} * (0.1*8)^0} {0!}\]

\[ Var(X)= E(X) = \lambda\]

\[ Var(X) = E(X) = (0.1)*(8)\]

pois_prob <- exp(-0.1*8)
pois_expected <- 0.1*8
pois_sd <- sqrt (pois_expected)
print(paste("The probability that the machine will fail after 8 years is",round(pois_prob,4),
            ",the expected value is ", round(pois_expected,2), 
            "and the standard deviation is ", round(pois_sd,4))) 
## [1] "The probability that the machine will fail after 8 years is 0.4493 ,the expected value is  0.8 and the standard deviation is  0.8944"

Poisson Approximation

Feller discusses the statistics of flying bomb hits in an area in the south of London during the Second World War. The area in question was divided into 24 * 24 = 576 small areas. The total number of hits was 537. There were 229 squares with 0 hits, 211 with 1 hit, 93 with 2 hits, 35 with 3 hits, 7 with 4 hits, and 1 with 5 or more. Assuming the hits were purely random, use the Poisson approximation to find the probability that a particular square would have exactly k hits. Compute the expected number of squares that would have 0, 1, 2, 3, 4, and 5 or more hits and compare this with the observed results.

Reference

\[ f(k ;\ \lambda) = \frac{\lambda^ke^{-\lambda}} {k!} \] Possible number of hits as k

\[ f(0 ;\ \lambda) + f(1 ;\ \lambda) + f(2 ;\ \lambda) + f(3 ;\ \lambda) + f(4 ;\ \lambda) + f(5 ;\ \lambda)\]

Lambda

\[ \lambda = \frac{537}{576}\]

round((537/576),2)
## [1] 0.93
poisson <- function(x,lambda)
{
  #formula above
  poisson <- ((lambda^x)*(exp(-lambda)))/(factorial(x))
  return (poisson)
}
#lambda = number of hits / number of small areas
lambda <- 537/576
#function calls possible number of hits 0,1,2,3,4,5
for (x in 0:5){
  #call above function
  temp <- poisson(x,lambda)
  #remove decimals and multiply by total number of small areas 
  value <- round(temp*576, 0)
  print(value)
}
## [1] 227
## [1] 211
## [1] 99
## [1] 31
## [1] 7
## [1] 1

Summary

hits <- c(0,1,2,3,4,5)
#given
observed <- c(229,211,93,35,7,1)
#calculated with above function
expected <- c(227,211,99,31,7,1)
data.frame(hits,observed,expected)
##   hits observed expected
## 1    0      229      227
## 2    1      211      211
## 3    2       93       99
## 4    3       35       31
## 5    4        7        7
## 6    5        1        1

Continuous Indepedent Trials

The price of one share of stock in the Pilsdorff Beer Company is given by \(Y_n\) on the nth day of the year. Finn observes that the differences \(X_n\) = \(Y_{n+1}\)\(Y_n\) appear to be independent random variables with a common distribution having mean μ = 0 and variance \(\sigma^2\) = 1/4. If \(Y_1\) = 100, estimate the probability that \(Y_{365}\) is \(\ge100\).

\[ \frac {100-100}{\sqrt{.25*(365-1)}} \]

Mean, Standard Deviation and n

#mean is given as 0, variance is given as 1/4
mu <- 0
var <- 0.25
#standard deviation is the sqrt of variance
sd <- sqrt (var)
n <- 365-1
part_a <- (100-100)/sqrt(n)
#use pnorm function to solve
pnorm (part_a, mu, sd, lower.tail= FALSE)
## [1] 0.5

Estimate the probability that \(Y_{365}\) is \(\ge110\).

\[ \frac {110-100}{\sqrt{.25*(365-1)}} \]

part_b <- (110-100)/sqrt(n)
#use pnorm function to solve
pnorm (part_b, mu, sd, lower.tail= FALSE)
## [1] 0.1472537

Estimate the probability that \(Y_{365}\) is \(\ge120\). \[ \frac {120-100}{\sqrt{.25*(365-1)}} \]

part_c <- (120-100)/sqrt(n)
#use pnorm function to solve
pnorm (part_c, mu, sd, lower.tail= FALSE)
## [1] 0.01801584

Moment Generating Function

Binomial

Calculate the expected value and variance of the binomial distribution using the moment generating function.

In order to calculate the expected value, we substitute zero into the first derivative of the moment generating function.

In order to calculate the variance, we substitute zero into the second derivative of the moment generating function and then subtract the expected value squared.

\[ \binom{n}{k}=\frac{n!} {(n-k)!k!} \]

\[ Probability|Mass|Function = \binom{n}{k} *p^k * (1-p)^{n-k} \]

Moment Generating Function

\[M(t) =\sum_{x = 0}^{n} e^{tx} \binom{n}{x} p^x (1-p)^{n-x}\]

\[M(t) =\sum_{x = 0}^{n} \binom{n}{x} (pe^t)^x (q)^{n-x}\] \[ = (pe^t + q)^n \]

Expected Value

\[ M'(t) = n(pe^t+q)^{n-1}pe^t \] We now substitute zero into the above first derivative

\[ E(X) = M'(0) = n(pe^0+q)^{n-1}pe^0 \] \[ E(X) = np \]

Variance

\[ M''(0) = n(n-1)p^2+np \] We now subtract the square of the expected value that we calculated above

\[ V(X) = M''(0) - (E(X))^2\] \[ V(X) = n(n-1)p^2+np - (np)^2\]

\[ V(X) = np^2(n-1)+np - (np)^2\] \[ V(X) = n^2p^2-np^2+np - n^2p^2\] \[ V(X) = np-np^2 \] \[ V(X) = np(1-p) \]

Exponential

Calculate the expected value and variance of the exponential distribution using the moment generating function.

Since PDF is \(\lambda e^{−λx}\) :

Moment Generating Function

\[\left[M(t) = \int_{0}^{\infty} e^{tx}\lambda e^{−λx} dx\right]\] \[\left[= \lambda \int_{0}^{\infty} e^{(t-\lambda)x} dx\right]\] \[=\left. \lambda \frac{e^{(t-\lambda)x}}{t-\lambda} \right|_{0}^{\infty}\] \[ = \frac {\lambda}{(\lambda-t)} \]

Expected Value

\[ M'(t) = \frac {\lambda}{(\lambda-t)^2} \]

We now substitute zero into the above first derivative

\[ E(X) = M'(0) = \frac {\lambda}{(\lambda-0)^2} \]

\[ E(X) = \frac{\lambda}{\lambda^2} = \frac{1}{\lambda} \]

Variance

\[ M''(t) = \frac {2\lambda}{(\lambda-t)^3} \] \[ M''(0) = \frac {2\lambda}{(\lambda-0)^3} \] \[ M''(0) = \frac {2}{\lambda^2} \] We now subtract the square of the expected value that we calculated above

\[ V(X) = M''(0) - (E(X))^2\]

\[ V(X) = \frac {2}{\lambda^2} - (\frac{1}{\lambda})^2\] \[ V(X) = \frac{1}{\lambda^2}\]

Calculus

Calculating Area

Find the total area enclosed by the functions f and g.

\[ f(x) = 2x^2+5x-3 \] \[ g(x) = x^2+4x-1 \]

Given Formula from Page 354:

Based on the above formula, we need to calculate a and b by setting the two functions equal to each other.

a and b are the intersection points

\[ f(x) = g(x) \] \[2x^2+5x-3 = x^2+4x-1\]

\[x^2+x-2 = 0\] \[ (x+2) (x-1) = 0\] \[ a = -2 \] \[b = 1\]

\[\left[Area = \int_{a}^{b} (f(x)-g(x) ) dx\right] \]

\[\left[Area = \int_{-2}^{1} \Large| x^2+x-2 | dx\right] \]

\[\left[Area = \int_{-2}^{1} -x^2-x+2 dx\right] \] \[=\left. \frac{-x^3}{3}- \frac{x^2}{2} +2x \right|_{-2}^{1}\]

\[Area = (\frac{-1^3}{3}- \frac{1^2}{2} +2(1)) - (\frac{-(-2)^3}{3}- \frac{(-2)^2}{2} +2(-2))\] \[Area = (\frac{-1}{3}- \frac{1}{2} +2) - (\frac{8}{3}- \frac{4}{2} -4)\]

\[Area = (\frac{-2}{6}- \frac{3}{6} + \frac{12}{6}) - (\frac{16}{6}- \frac{12}{6} -\frac{24}{6})\] \[Area = (\frac{7}{6}) - (-\frac{20}{6})\]

The total area enclosed by the functions \(f(x) = 2x^2+5x-3\) and \(g(x) = x^2+4x-1\) is \(\frac{27}{6}\) or 4.5


Find the total area of the red rectangles in the figure below, where the equation of the line is \(f ( x ) = 2x - 9\).

Based on the above figure, the rectangles start at x = 4.5 and end at x = 8.5

We will integrate the function at these points to find the area.

\[\ \int_{4.5}^{8.5} 2x - 9 dx \] \[=\left. \ {x^2} -9x \right|_{4.5}^{8.5}\]

\[Area = ({8.5^2} -9(8.5)) - ({4.5^2} -9(4.5)) \] \[Area = (72.25- 76.5) - (20.25-40.5)\]

\[Area = (-4.25) - (-20.25)\]

Area of the red rectangles is 16.


Find the area of the region bounded by the graphs of the given equations.

\[ y = x^2 - 2x - 2, y = x + 2 \]

\[ x^2 - 2x -2 = x + 2\] \[ x^2 - 3x -4 = 0\]

\[(x-4)(x+1)=0\] x = 4, x = -1

The graph below illustrates these intersection points

y1 <- function (x) 
{return (x**2-2*x-2)}
y2 <- function (x)
{return (x+2)}
x <- seq (-3,6,1)
y <- y2 (x)
plot (y1, from = -3, to = 6, line = "l", col = '#7fcdbb')
lines (x,y, col = '#fc9272')

\[\ \int_{-1}^{4} (x+2)-(x^2-2x-2) dx \]

\[\ \int_{-1}^{4} -x^2+3x+4dx \] \[=\left. \ \frac{-x^3}{3}+ \frac{3x^2}{2} +4x \right|_{-1}^{4}\] \[Area = (\frac{-4^3}{3}+ \frac{3*(4)^2}{2} +4(4)) - (\frac{-(-1)^3}{3}+ \frac{3*(-1)^2}{2} +4(-1)) \] \[Area = (\frac {-64}{3} + \frac{48}{2} + 16) - (\frac{1}{3}+ \frac {3}{2} - 4) \] \[Area = (\frac {-128}{6} + \frac{144}{6} + \frac{96}{6}) - (\frac{2}{6}+ \frac {9}{6} - \frac{24}{6}) \] \[Area = (\frac{112}{6}) - (\frac{-13}{6})\]

Area of the region bounded by the graphs is \(\frac{125}{6}\) or \(20.\overline{83}\)

Integration by Substitution

Use integration by substitution to solve the integral below.

\[\int_{}^{}4e^{-7x}dx\] \[ u = -7x \]

\[ \frac {du}{dx} = -7 \]

\[ du = -7dx \]

\[ dx = \frac {du}{-7}\] \[ \frac {-4}{7} \int e^udu \] \[ = \frac {-4}{7} * e^u \] Substitute -7x for u \[ =\frac {-4e^{-7x}}{7} + c\]

Integration by Parts

Use integration by parts to solve the integral below.

\[\int_{}^{}ln(9x)*x^6dx\] Formula \[\int fg' = fg - \int f'g\] \[ f = ln(9x)\] \[ f' = \frac{1}{x}\] \[g' = x^6\] \[g = \frac{x^7}{7}\] Substitute into formula \[\int ln(9x)*x^6 = ln(9x)*\frac{x^7}{7} - \int \frac{1}{x} * \frac{x^7}{7}\] \[ = ln(9x)*\frac{x^7}{7} - \int \frac{x^6}{7}\]

\[ = \frac { ln(9x)* x^7}{7} - \frac {x^7}{49}\] \[ = \frac { 7* ln(9x)* x^7}{49} - \frac {x^7}{49}\]

\[ = \frac {( 7x^7* ln(9x)) - x^7}{49} \] \[ = \frac {x^7( 7ln(9x)-1) }{49} + c\]

Double Integral

Evaluate the double integral on the given region.

\[\underset{R}{\iint} (e^{8x+3y})dA;R:2\le x\le4, 2\le y\le4\]

u=8x+3y, du = 8

\[\ \frac{1}{8}\int_{2}^{4} e^u du \]

\[=\left. \ \frac{e^{8x+3y}}{8}\right|_{2}^{4}\] \[=\ \frac{e^{8(4)+3y}}{8} - \frac{e^{8(2)+3y}}{8}\] \[=\ \frac{e^{32+3y}}{8} - \frac{e^{16+3y}}{8}\]

\[\ \int_{2}^{4} \frac{e^{32+3y}-e^{16+3y}}{8} dy \] Separate into two integrals

\[ \frac{1}{8}\int_{2}^{4} e^{32+3y} dy -\frac{1}{8}\int_{2}^{4} e^{16+3y} dy\]

\[=(\frac{1}{8})\left. \ \frac{e^{32+3y}}{3}\right|_{2}^{4}-(\frac{1}{8})\left. \ \frac{e^{16+3y}}{3}\right|_{2}^{4}\] \[=\ (\frac{1}{8})(\frac{e^{32+3(4)}}{3} - \frac{e^{32+3(2)}}{3})- (\frac{1}{8})(\frac{e^{16+3(4)}}{3} - \frac{e^{16+3(2)}}{3})\]

\[=\ (\frac{1}{8})(\frac{e^{32+12}}{3} - \frac{e^{32+6}}{3})- (\frac{1}{8})(\frac{e^{16+12}}{3} - \frac{e^{16+6}}{3})\] \[=\ \frac{e^{44}}{24} - \frac{e^{38}}{24}- \frac{e^{28}}{24} + \frac{e^{22}}{24}\]

Probability Density Function

Determine whether \(f ( x )\) is a probability density function on the interval \([1, e^6]\). If not, determine the value of the definite integral.

\[ f(x) = \frac {1}{6x}\]

A function is a probability density function if it integrates over the domain of the variable to 1

\[\ \int_{1}^{e^6} \frac {1}{6x}dx \] \[ \frac{1}{6} \int_{1}^{e^6} \frac {1}{x}dx\] \[=(\frac{1}{6})\left. \ ln(x) \right|_{1}^{e^6}\]

\[=(\frac{1}{6}) (ln(e^6)) - (\frac{1}{6})(ln(1)) \]

Since \(ln(1) = 0\) , we are left with the following:

\[=(\frac{1}{6}) 6(ln(e)) \]

\[ = ln(e) = 1\]

\(f ( x ) = \frac {1}{6x}\) is a probability density function on the interval \([1, e^6]\)

Partial Derivative

Evaluate \(f_x (x, y)\) and \(f_y (x, y)\) at the indicated point \((\frac{\pi}{3},\frac{\pi}{3})\).

\[f(x,y) = sin(y)cos(x)\]

Partial Derivative (Page 703)

For \(f_x\) treat \(y\) as a constant

Take constant out \((a*f') = a*f'\)

\[f_x = sin(y)(-sin(x))\]

For \(f_y\) treat \(x\) as a constant

Take constant out \((a*f') = a*f'\) \[f_y= cos(y)cos(x)\]

Trigonometry Review

sin(x) cos(x) tan(x)
0 = 0 0 =1 0=0
\(\frac{\pi}{6} = \frac{1}{2}\) \(\frac{\pi}{6}= \frac{\sqrt3}{2}\) \(\frac{\pi}{6}=\frac{1}{\sqrt3}\)
\(\frac{\pi}{4} = \frac{\sqrt2}{2}\) \(\frac{\pi}{4}=\frac{\sqrt2}{2}\) \(\frac{\pi}{4}=1\)
\(\frac{\pi}{3}= \frac{\sqrt3}{2}\) \(\frac{\pi}{3}= \frac{1}{2}\) \(\frac{\pi}{3}=\sqrt3\)
\(\frac{\pi}{2}=1\) \(\frac{\pi}{2}= 0\) \(\frac{\pi}{2}\)=undefined

Using the values above, we can substitute the indicated point \((\frac{\pi}{3},\frac{\pi}{3})\) into \(f_x\) and \(f_y\)

\(f_x\)

\[f_x = sin(y)(-sin(x))\] \[f_x = sin(\frac{\pi}{3})(-sin(\frac{\pi}{3}))\] \[f_x = \frac{\sqrt3}{2} (-\frac{\sqrt3}{2})\] \[f_x=\frac{-3}{4}\]

\(f_y\)

\[f_y= cos(y)cos(x)\]

\[f_y= cos(\frac{\pi}{3})cos(\frac{\pi}{3})\] \[f_y= \frac{1}{2}*\frac{1}{2}\] \[f_y=\frac{1}{4}\]

Local Maxima, Local Minima, Saddle Points

Find all local maxima, local minima, and saddle points for the function given below. Write your answer(s) in the form (x, y, z). Separate multiple points with a comma.

\[ f(x,y) = 24x-6xy^2-8y^3\]

Partial Derivative

\[f_x = 24 - 6y^2\] \[f_y = -12xy - 24y^2\]

Critical Points

Set \(f_x = 0\)

\[24-6y^2=0\] \[24=6y^2\] \[4=y^2\] \[\pm2 = y\] Substitute y-values into \(f_y =0\)

\[-12xy - 24y^2=0\] \[xy+2y^2=0\] Substitute y=2 \[x(2) + 2(2)^2 = 0\]

\[2x+8=0\] \[2x=-8\] \[x=-4\]

Substitute y=-2 \[x(-2) + 2(-2)^2 = 0\]

\[-2x+8=0\] \[-2x=-8\] \[x=4\] Substitute (x,y) values for z \[ f(x,y) = 24x-6xy^2-8y^3\] Substitute (-4,2)

\[ z = 24(-4)-6(-4)(2)^2-8(2)^3\] \[z = -96+96-64\] \[z=-64\] Substitute (4,-2)

\[ z = 24(4)-6(4)(-2)^2-8(-2)^3\] \[z = 96-96+64\] \[z=64\]

Critical points are (-4,2,-64) and (4,-2,64)

Referring to the definition in page 752 of the textbook

\[f_{xx} = 0\] \[f_{yy} = -12x - 48y\] \[f_{xy} = - 12y\] Plug into formula \[ D = f_{xx}(x,y)*f_{yy}(x,y) - f_{xy}^2(x,y)\]

\[ D = 0(x,y)*(-12x - 48y(x,y) )- (- 12y)^2(x,y)\] \[ D = 0- 144y^2(x,y)\] \[D = -144y^2(x,y)\]

If we plug in y=2 or y=-2, we get D<0 concluding critical points (-4,2,-64) and (4,-2,64) are both saddle points.

Biology Application

Biologists are treating a pond contaminated with bacteria. The level of contamination is changing at a rate of \(\frac{dN}{dt} = -\frac{3150}{t^4}-220\) bacteria per cubic centimeter per day, where t is the number of days since treatment began. Find a function \(N( t )\) to estimate the level of contamination if the level after 1 day was 6530 bacteria per cubic centimeter.

\[\frac{dN}{dt} = -\frac{3150}{t^4}-220\] \[\frac{dN}{dt} = -3150t^{-4}-220\]

\[ N( t ) = \int -3150t^{-4}-220 dt \] \[ = \frac {-3150t^{-3}}{-3} - 220t + c\]

\[ N(t) = \frac {1050}{t^3} - 220t + c\] Given level of contamination after 1 day was 6530 bacteria per cubic centimeter:

\[ 6530 = \frac {1050}{1^3} - 220(1) + c \]

\[ 6530 = 830 + c \] \[ c = 5700 \]

Thus:

\[N(t) = \frac {1050}{t^3} - 220t + 5700\]

Minimize Costs

A beauty supply store expects to sell 110 flat irons during the next year. It costs $3.75 to store one flat iron for one year. There is a fixed cost of $8.25 for each order. Find the lot size and the number of orders per year that will minimize inventory costs.

Number of orders (x) * Lot Size (n) = 110

C = costs

\[ C = 8.25x + 3.75 * \frac {110/x}{2}\] \[ C = 8.25x + 3.75 * \frac {55}{x}\]

\[ C = 8.25x + \frac{206.25}{x}\]

In order to minimize costs, set derivative = zero

\[ C' = 8.25 - \frac{206.25}{x^2}\] \[0 =8.25 - \frac{206.25}{x^2}\]

\[ \frac{206.25}{x^2} = 8.25\]

\[206.25 = 8.25x^2\]

\[\frac{206.25}{8.25} = x^2\]

\[25 = x^2\]

Thus, the number of orders per year that will minimize inventory costs is 5. The lot size is 22 because 22 x 5 = 110


A company has a plant in Los Angeles and a plant in Denver. The firm is committed to produce a total of 96 units of a product each week. The total weekly cost is given by \(C(x,y)= \frac{1}{6}x^2 + \frac{1}{6}y^2 +7x+25y+700\), where x is the number of units produced in Los Angeles and y is the number of units produced in Denver. How many units should be produced in each plant to minimize the total weekly cost?

Given \(x+y=96\)

y=96-x

Substitute (96-x) into y \[C(x,y)= \frac{1}{6}x^2 + \frac{1}{6}y^2 +7x+25y+700\]

\[C(x,y)= \frac{1}{6}x^2 + \frac{1}{6}(96-x)^2 +7x+25(96-x)+700\] \[C(x,y)= \frac{1}{6}x^2 + \frac{1}{6}(9216-192x+x^2) +7x+2400-25x+700\] \[C(x,y)= \frac{1}{6}x^2 + 1536-32x+\frac{x^2}{6} +7x+2400-25x+700\] \[C(x,y)= \frac{1}{3}x^2-50x+4636\]

\[C'= \frac{2}{3}x-50\] \[0 = \frac{2}{3}x-50\] \[50 = \frac{2}{3}x\]

\[75 = x\]

Thus the number of units produced in Los Angeles to minimize the total weekly cost is 75 units. If a total of 96 units are produced each week, the remaining 21 units are produced in Denver (\(y=21\)).

#define the function as only a function of x
C <- function(x){1/3*(x^2) -50*x + 4636}
#plot labels
plot(C(0:96), type='l', main= 'Los Angeles Production', xlab = 'Units Produced', 
ylab = 'Total Weekly Cost ($)')
#point where total weekly cost is at the minimum
points(75, 2761, pch=8, col="#009999")

Revenue Function

A grocery store sells two brands of a product, the “house” brand and a “name” brand. The manager estimates that if she sells the “house” brand for x dollars and the “name” brand for y dollars, she will be able to sell \(81 - 21x + 17y\) units of the “house” brand and \(40 + 11x - 23y\) units of the “name” brand.

Step 1. Find the revenue function \(R ( x, y )\).

Revenue = units sold x price

\[R(x,y) = x(81-21x+17y) + y(40+11x-23y)\]

\[R(x,y)=81x-21x^2+17xy + 40y+11xy-23y^2\]

\[R(x,y)=-21x^2-23y^2+28xy+81x+40y\]

Step 2. What is the revenue if she sells the “house” brand for $2.30 and the “name” brand for $4.10?

\[R(2.3,4.1)=-21(2.3)^2-23(4.1)^2+28(2.3)(4.1)+81(2.3)+40(4.1)\]

#house brand price
x <- 2.3
#name brand price
y <- 4.1
#revenue function from step 1
revenue <- -21*x^2-23*y^2+28*x*y+81*x+40*y
#answer
print(paste("$",revenue))
## [1] "$ 116.62"

Taylor and Maclaurin Series

Find a formula for the \(n^{th}\) term of the Taylor series of \(f(x)\), centered at c, by finding the coefficients of the first few powers of x and looking for a pattern.

\[ f(x) = \cos x \] \[ c = \pi/2 \] \[f(x) =\sum_{n = 0}^{\infty} \frac{f^{(n)}(c)}{n!} \ (x-c)^{n}\]

n = 0

\[\frac{f^{(0)}( \pi/2)}{0!} \ (x- \pi/2)^{0}\] \[\frac {\cos ( \pi/2)}{1} \ (x- \pi/2)^{0}\] Since \(\cos (\pi/2)\) is zero, the result is zero.

n = 1

\[\frac{f^{(1)}( \pi/2)}{1!} \ (x- \pi/2)^{1}\] \[= \frac {-\sin ( \pi/2)}{1} \ (x- \pi/2)^{1}\] \[= -(x- \pi/2)\]

n = 2

\[\frac{f^{(2)}( \pi/2)}{2!} \ (x- \pi/2)^{2}\] \[ \frac {-\cos ( \pi/2)}{2} \ (x- \pi/2)^{2}\] Since \(-\cos (\pi/2)\) is zero, the result is zero.

n = 3

\[\frac{f^{(3)}( \pi/2)}{3!} \ (x- \pi/2)^{3}\]

\[= \frac {\sin ( \pi/2)}{6} \ (x- \pi/2)^{3}\] \[= \frac {(x- \pi/2)^{3}} {6}\]

n = 4

\[\frac{f^{(4)}( \pi/2)}{4!} \ (x- \pi/2)^{4}\] \[\frac {\cos ( \pi/2)}{24} \ (x- \pi/2)^{4}\]

Since \(\cos (\pi/2)\) is zero, the result is zero. We also notice that the cycle has started back at \(f^0\) or \(f(x) = \cos x\)

Summary: The pattern is \(f(x) = \cos x\),

\(f'(x) = -\sin x\),

\(f''(x) = -\cos x\),

\(f'''(x) = \sin x\),

\(f''''(x) = \cos x\)

If we refer back to the first few powers calculated above, we have the following:

\[ 0 + -(x- \pi/2) + 0 + \frac {(x- \pi/2)^{3}} {6} + 0 \]

Thus, for the \(n^{th}\) term of the Taylor series of \(f(x) = \cos x\), centered at \(\frac{\pi}{2}\) we can use the following formula:

\[\sum_{n = 0}^{\infty}\frac{{(-1)^{n+1}}}{(2n+1)!} (x-c)^{2n+1} \ \]


For each function, only consider its valid ranges as indicated in the notes when you are computing the Taylor Series expansion.

Referring to the definition in page 485 of the textbook

\(f(x) = \frac{1}{(1-x)}\)

Interval of Convergence is (-1,1)

In order to find the pattern, we find the first few derivatives and evaluate them at 0.

\[ f(x) = \frac{1}{(1-x)} = (1-x)^{-1} \] \[ f(0) = \frac{1}{(1-0)} = (1-0)^{-1} = 1\] \[ f'(x) = (1-x)^{-2} \] \[ f'(0) = (1-0)^{-2} = 1 \]

\[ f''(x) = 2(1-x)^{-3} \] \[ f''(0) = 2(1-0)^{-3} = 2\] \[ f'''(x) = 6(1-x)^{-4} \] \[ f'''(0) = 6(1-0)^{-4}=6 \] \[ f''''(x) = 24(1-x)^{-5} \] \[ f''''(0) = 24(1-0)^{-5} =24\] \[ f'''''(x) = 120(1-x)^{-6} \] \[ f'''''(0) = 120(1-0)^{-6} =120\]

Based on the factorial pattern (1,2,6,24,120…) from the first few derivatives, we can conclude the following:

\[ f^{n}(x) = n!(1-x)^{(-n-1)}=\frac{n!}{(1-x)^{n+1}} \] Thus \[f^{n}(0) = n!\]

Plug \(n!\) into Maclaurin Series definition

\[\sum_{n = 0}^{\infty}\frac{{f^{n}(0)}}{n!} (x)^{n} \ \]

After plugging in, we are left with

\[\sum_{n = 0}^{\infty}(x)^{n} \ \] \[\sum_{n = 0}^{\infty}(x)^{n} = 1 + x + x^2 + x^3 + etc.\ \]


\(f(x) = e^x\)

Interval of Convergence is \((-\infty, \infty )\)

The function \(f(x) = e^x\) is equivalent to its derivative functions.

\(f'(x) =e^x\),

\(f''(x) = e^x\),

\(f'''(x) = e^x\),

\(f''''(x) = e^x\)

We can conclude the following:

\[f^{n}(x) = e^x\] Thus \[f^{n}(0) = 1\]

Plug 1 into Maclaurin Series definition

\[\sum_{n = 0}^{\infty}\frac{{f^{n}(0)}}{n!} (x)^{n} \ \]

After plugging in, we are left with

\[\sum_{n = 0}^{\infty}\frac{1}{n!}(x)^{n} \ \]

\[\sum_{n = 0}^{\infty}\frac{(x)^{n}}{n!} = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24}+etc.\ \]


\(f(x) = ln(1+x)\)

\[ f(x) = ln(1+x) \] \[ f(0) = ln(1+0) =0\] \[ f'(x) = \frac{1}{1+x} = (1+x)^{-1} \] \[ f'(0) = \frac{1}{1+0} = (1+0)^{-1} = 1 \]

\[ f''(x) = -(1+x)^{-2} \] \[ f''(0) = -(1+0)^{-2} = -1\] \[ f'''(x) = 2(1+x)^{-3} \] \[ f'''(0) = 2(1+0)^{-3}=2 \] \[ f''''(x) = -6(1+x)^{-4} \] \[ f''''(0) = -6(1+0)^{-4} =-6\] \[ f'''''(x) = 24(1+x)^{-5}\]

\[ f'''''(0) = 24(1+0)^{-5} =24\]

Based on the pattern from the first few derivatives, we can conclude the following:

\[ f^{n}(x) = (-1)^{n+1}(n-1)!(1+x)^{-n}=(-1)^{n+1}\frac{(n-1)!}{(1+x)^n} \] Thus \[f^{n}(0) = (-1)^{n+1}(n-1)!\] Plug \((-1)^{n+1}(n-1)!\) into Maclaurin Series definition

\[\sum_{n = 0}^{\infty}\frac{{f^{n}(0)}}{n!} (x)^{n} \ \]

After plugging in, we are left with

\[\sum_{n = 0}^{\infty}\frac{((-1)^{n+1}(n-1)!)}{n!}(x)^{n} \ \] It is important to note that after simplifying, the denominator is n. Since n cannot be equal to zero, I will start at n = 1 \[\sum_{n = 0}^{\infty}\frac{(-1)^{n+1}(x)^{n}}{n} = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4}+ etc.\ \]

Textbook Reference

A First Course in Linear Algebra, Beezer, R., 2008

Introduction to Probability, Grinstead, C. Snell, J., 1997

APEX Calculus, Hartman, G. 2014