library(pracma)

1

Find the equation of the regression line for the given points. The points given are (5.6, 8.8), (6.3, 12.4), (7, 14.8), (7.7, 18.2), (8.4, 20.8).

x <- c(5.6, 6.3, 7, 7.7, 8.4)
y <- c(8.8, 12.4, 14.8, 18.2, 20.8)

regression <- lm(y ~ x)
summary(regression)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##     1     2     3     4     5 
## -0.24  0.38 -0.20  0.22 -0.16 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -14.8000     1.0365  -14.28 0.000744 ***
## x             4.2571     0.1466   29.04 8.97e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3246 on 3 degrees of freedom
## Multiple R-squared:  0.9965, Adjusted R-squared:  0.9953 
## F-statistic: 843.1 on 1 and 3 DF,  p-value: 8.971e-05

y=-14.8 +4.26x

2

Find all local maxima, minima, and saddle points for the function. The function is \(f(x, y) = 24x - 6xy^2 - 8y^3\). Write your answer(s) in the form ( x, y, z ). Separate multiple points with a comma.

df_dx_as_function_of_y <- function(y) {
  24 - 6 * y^2
}


df_dy_as_function_of_x <- function(x, y_value) {
  -12 * x * y_value - 24 * y_value^2
}


y_values <- c(2, -2)

x_values <- sapply(y_values, function(y) {

  uniroot(df_dy_as_function_of_x, c(-10, 10), y_value = y)$root
})


critical_points <- cbind(x_values, y_values)


z_values <- sapply(1:nrow(critical_points), function(i) {
  x <- critical_points[i, 1]
  y <- critical_points[i, 2]
  24*x - 6*x*y^2 - 8*y^3 
})


critical_points_with_z <- cbind(critical_points, z_values)


print(critical_points_with_z)
##          x_values y_values z_values
## x_values       -4        2      -64
## x_values        4       -2       64

two critical points \((-4, 2, -64)\), \((4, -2, 64)\)

The second derivative test states that for a critical point \((x_0, y_0)\):

  • If \(D > 0\) and \(\frac{\partial^2 f}{\partial x^2} > 0\), then \(f\) has a local minimum at \((x_0, y_0)\).
  • If \(D > 0\) and \(\frac{\partial^2 f}{\partial x^2} < 0\), then \(f\) has a local maximum at \((x_0, y_0)\).
  • If \(D < 0\), then \(f\) has a saddle point at \((x_0, y_0)\).
  • If \(D = 0\), the test is inconclusive.

Compute the second partial derivatives:

  • \(\frac{\partial^2 f}{\partial x^2} = 0\)
  • \(\frac{\partial^2 f}{\partial y^2} = -12x - 48y\)
  • \(\frac{\partial^2 f}{\partial x \partial y} = -12y\)

Calculate \(D\) for each critical point:

  • For \((-4, 2, -64)\): \(D = (0) \times (-12 \times (-4) - 48 \times 2) - (-12 \times 2)^2 = -576\)
  • For \((4, -2, 64)\): \(D = (0) \times (-12 \times 4 - 48 \times (-2)) - (-12 \times (-2))^2 = -576\)

Since \(D < 0\) for both critical points, they are both saddle points. There are no local maxima or minima.

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)\).

R <- function(x, y) { (81 - 21*x + 17*y)*x + (40 + 11*x - 23*y)*y }

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

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

revenue <- R(2.3, 4.1)
revenue
## [1] 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 + 7*x + 25*y + 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?

total_units <- 96

C_single_var <- function(x) {
  y <- total_units - x  
  (1/6)*x^2 + (1/6)*y^2 + 7*x + 25*y + 700
}

optim_result <- optim(48, C_single_var, method = "L-BFGS-B", lower = 0, upper = total_units)

x_optimal <- optim_result$par

y_optimal <- total_units - x_optimal


cat("Optimal production in Los Angeles (x):", x_optimal)
## Optimal production in Los Angeles (x): 75
cat("Optimal production in Denver (y):", y_optimal)
## Optimal production in Denver (y): 21
cat("Minimum total weekly cost:", optim_result$value)
## Minimum total weekly cost: 2761

5

Evaluate the double integral on the given region.

The region R: \[\iint_R (e^{8x+3y})dA;R:2\le x \le 4 and 2 \le y \le 4\].

Write your answer in exact form without decimals.

integrand <- function(x, y) { exp(8*x + 3*y) }
xmin <- 2 
xmax <- 4
ymin <- 2 
ymax <- 4
integral2(integrand,xmin,xmax, ymin, ymax)
## $Q
## [1] 5.341559e+17
## 
## $error
## [1] 15214781905