Assignment 15

1.

Find the equation of the regression line for the given points. Round any final values to the nearest hundredth, if necessary. ( 5.6, 8.8 ), (6.3, 12.4 ), ( 7, 14.8 ), ( 7.7, 18.2 ), ( 8.4, 20.8 )

# define the points by x and y values
x <- c(5.6, 6.3, 7, 7.7, 8.4)
y <- c(8.8, 12.4, 14.8, 18.2, 20.8)

# linear regression
regression <- lm(y ~ x)

# indices allows access specific elements with out them it would print twice
slope <- coef(regression) [2]
intercept <- coef(regression) [1]

# the equation of the regression line
cat("The equation of the regression line is: y =", round(slope, 2), "x", round(intercept, 2), "\n")
## The equation of the regression line is: y = 4.26 x -14.8

2.

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

  • looking for critical points

Given function is \(f(x, y) = 24x - 6xy^2 - 8y^3\).

Calculate the partial derivatives: \[ f_x = \frac{\partial f}{\partial x} = 24 - 6y^2 \] \[ f_y = \frac{\partial f}{\partial y} = -12xy - 24y^2\]

Find critical points by setting both partial derivatives to zero:

For \(f_x = 0\): \[ 24 - 6y^2 = 0 \] Solving for y, we get \(y = \pm 2\).

When y = 2, x = -4. Thus, one critical point is (-4, 2).

When y = -2, x = 4. Thus, another critical point is (4, -2).

For \(f_y = 0\): \[ -12xy - 24y^2 = 0 \] Solving for x, we get x = -2y.

The outcome is the same critical points when y = 2, x = -4 and when y = -2, x = 4 as above.

Next evaluate the function at these critical points: (-4, 2): \[ f(-4, 2) = 24(-4) - 6(-4) \cdot 2^2 - 8 \cdot 2^3 = -64 \] evaluate the function at these critical points: (4, -2): \[ f(4, -2) = 24(4) - 6(4) \cdot (-2)^2 - 8 \cdot (-2)^3 = 64 \] the critical point (-4, 2, -64) and (4, -2, 64) is a saddle point

3.

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 ). - the first equation * x dollars - the second equation * y dollars

R(x,y)=x⋅(81−21x+17y)+y⋅(40+11x−23y)

Step 2. What is the revenue if she sells the “house” brand for $2.30 and the “name” brand for $4.10? - plug in the values and solve or I did it in R to try it out

# revenue function
r_function <- function(x, y) {
  price_house <- x
  price_name <- y

  quantity_house <- 81 - 21 * x + 17 * y
  quantity_name <- 40 + 11 * x - 23 * y

  revenue <- price_house * quantity_house + price_name * quantity_name

  return(revenue)
}

# prices in step 2
house_given <- 2.30
name_given <- 4.10

#calculate the revenue
total_revenue <- r_function(house_given, name_given)

# Print the result
cat("The total revenue given the prices provided is $", round(total_revenue, 2), "\n")
## The total revenue given the prices provided is $ 116.62

4.

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) = 1/6 x ^2 + 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?

To minimize the total weekly cost, find the the partial derivatives and equal to zero to find the critical points

\[\frac{\partial C}{\partial x} = \frac{1}{3}x + 7 = 0 \implies x = -21\]

\[\frac{\partial C}{\partial y} = \frac{1}{3}y + 25 = 0 \implies y = -75\]

the critical point (-21, -75) is a local minimum, since it is not possible to have negative units I’m assuming the 21 units is produced in Los Angeles and 75 units is produced in Denver to minimize the weekly cost - I want to also try it in R to see if I get the same results

# define the given cost function
cost_function <- function(x, y) {
  return((1/6)*x^2 + (1/6)*y^2 + 7*x + 25*y + 700)
}

# define constraint, firm is committed to produce a total of 96 units total
constraint <- function(y) {
  x <- 96 - y
  return(cost_function(x, y))
}

# find the minimum 
result <- optimize(constraint, interval = c(0, 96))

# extract the optimized values, x = 96 - y
x_optimal <- 96 - result$minimum  

cat("Optimal number of units produced in Los Angeles:", x_optimal, "\n")
## Optimal number of units produced in Los Angeles: 75
cat("Optimal number of units produced in Denver:", result$minimum, "\n")
## Optimal number of units produced in Denver: 21

5.

Evaluate the double integral on the given region.

\[ \int \int e^{8x + 3y} \,dy \,dx \quad \text{over} \quad 2 \leq x \leq 4 \quad \text{and} \quad 2 \leq y \leq 4 \] Write your answer in exact form without decimals.

#integrate fucntion is only for 1 dimensions

library(pracma)

# define the function
f <- function(x, y) {
  exp(8 * x + 3 * y)
}

# double integral
result <- integral2(f, xmin = 2, xmax = 4, ymin = 2, ymax = 4)

result
## $Q
## [1] 5.341559e+17
## 
## $error
## [1] 15214781912
#no decimals - remove the e notation

cat("The exact form without decimals is", format(result$Q, scientific = FALSE), "\n")
## The exact form without decimals is 534155947871806976