1. Use integration by substitution to solve the integral below: \(\int 4e^{-7x} \, dx\)

integral <- function(x) {
  -4/7 * exp(-7 * x)
}

integral(0) # for example to evaluate when x = 0
## [1] -0.5714286

2. 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.

# rate of change of contamination: dN/dt = -3150/t^4 - 220

# We integrate -3150/t^4 to get 1050/t^3
# Then we integrate -220 to get -220t.
# And then we combine results: N(t) = 1050/t^3 - 220t + C

# Now we apply the initial condition (N(1) = 6530) to find C:
# 1050/1^3 - 220*1 + C = 6530 => C = 5700

# Finally, our model for contamination is: N(t) = 1050/t^3 - 220t + 5700

N <- function(t) {
  1050 / t^3 - 220 * t + 6800
}
N(5)  # Evaluate N(t) at t = 5
## [1] 5708.4

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

f <- function(x) {
  2 * x - 9
}

total_area <- 0

for (x in 5:8) {  # based on the grid the rectangles are at x=5, x=6, x=7, and x=8
  height <- f(x)
  if (height > 0) { 
    total_area <- total_area + height
  }
}

total_area
## [1] 16

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

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

# the roots of the equation x^2 - 3x - 4 = 0
roots <- polyroot(c(-4, -3, 1))
# we extract the real parts of the roots
exroots <- Re(roots)

f1 <- function(x) { x^2 - 2*x - 2 }
f2 <- function(x) { x + 2 }

# Calculate the area between the two curves from the smallest to the largest root
area <- integrate(function(x) abs(f1(x) - f2(x)), min(exroots), max(exroots))

area$value
## [1] 20.83333

5. 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.

# to get the number of orders per year that will minimize inventory cost we need to calculate the economic order quantity (EOQ)

# Formula of EOQ = sqrt 2DP/ C
# D = demand, P = ordering cost per PO, C = Carrying costs

D <- 110
P <- 8.25
C <- 3.75

# Economic Order Quantity (EOQ)
EOQ <- sqrt((2 * D * P) / C) 

N_orders <- D / EOQ

annual_cost <- (D / EOQ) * P + (EOQ / 2) * C

list(EOQ = EOQ, N_orders = N_orders, annual_cost = annual_cost)
## $EOQ
## [1] 22
## 
## $N_orders
## [1] 5
## 
## $annual_cost
## [1] 82.5

6. Use integration by parts to solve the integral below. \[ \int \ln(9x) \ . \ x^6 dx \]

# We choose u to be ln(9x) because its derivative is simpler, and dv to be x^6 dx for straightforward integration.

# We then differentiate u to get du = 1/x dx, and integrate dv to get v = x^7/7.

# Applying the integration by parts formula (integral of u dv = u v - integral of v du), we multiply u and v.

# We subtract the integral of v du from u v to get the final integrated function.

# We conclude that the integral of ln(9x) * x^6 dx equals (x^7/7) * ln(9x) minus the integral of x^6 dx, 

# which simplifies to (x^7/7) * ln(9x) - x^7/49.

integral_by_parts <- function(x) {
  x^7 / 7 * (log(9*x) - 1)
}
integral_by_parts(1)  # Evaluate at x = 1
## [1] 0.1710321

7. 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} \]

Answer: First, we need to prove that the definite integral of \(f(x)\) over the interval \([1, e^6]\) is equal to 1 to satisfy one of the requirements for a probability density function (PDF).

If the integral is equal to 1, then \(f(x) = \frac{1}{6x}\) can be considered a PDF.

f <- function(x) 1 / (6 * x)

result <- integrate(f, lower = 1, upper = exp(6))
result
## 1 with absolute error < 9.3e-05
# With an absolute error < 9.3e-05, we confirm that the function satisfies the condition required for it to be a probability density function (PDF), since the total integral over its defined range equals 1.

# Another way to verify our result:
is_pdf <- abs(result$value - 1) < .Machine$double.eps^0.5
is_pdf
## [1] TRUE
# TRUE indicates that the function f(x) is indeed a PDF