We can compute the indefinite integral of \(\frac{dN}{dt}\) to get an expression for \(N(t)\). From there we can use our boundary condition (\(N(1) = 6530\)) to find an expression
\[\begin{aligned} N(t) = \int \frac{-3150}{t^4} - 220 \,dx = \frac{1050}{3t^3} - 220x + C \end{aligned}\]Now we can plug in our boundary condition to find our constant of integration \(C\):
\[\begin{aligned} N(1) = 6530 = \frac{1050}{3(1)^3} - 220(1) + C\newline = 350 - 220 + C\newline C = 6530 - 350 + 220 \end{aligned}\]C <- 6530 - 350- 220
print(C)
## [1] 5960
Making our final expression for the number of bacteria per day: \(N(t) = \frac{1050}{3t^3} + 5960\)
N <- function(t, c=C){
1050/(3* t^3) + c
}
(N_prime <- deriv(expression(N), "t"))
## expression({
## .value <- N
## .grad <- array(0, c(length(.value), 1L), list(NULL, c("t")))
## .grad[, "t"] <- 0
## attr(.value, "gradient") <- .grad
## .value
## })
f <- function(x){
2 * x - 9
}
x_vals <- c(5, 6, 7, 8)
# Iterate over rectangles (width = 1). and sum up area of riemann rectangles
area <- 0
for (x in x_vals){
rect_area <- 1 * f(x)
area <- area + rect_area
}
print(area)
## [1] 16
Let’s define our functions in question as:
\[\begin{aligned} g(x) = x + 2\newline h(x) = x^2 - 2x - 2 \end{aligned}\]We can solve this by finding where these functions equal each other (\(g(x) = h(x)\)), then subtract the definite integral of each function over that interval (assuming only 2 intercepts)
g <- function(x){
x + 2
}
h <- function(x){
x^2 - 2*x - 2
}
# Plotting our functions
curve(h, from =-5, to=5, col=2)
curve(g, from =-5, to=5, col=3, add=TRUE)
Visually, it looks like these functions intersect at \(x = -1, 4\). We can solve this intersect analytically:
\[\begin{aligned} x + 2 = x^2 - 2x - 2\newline 0 = x^2 - 3x - 4\newline 0 = (x - 4)(x - 1) \end{aligned}\]Confirming our intuition above, this equation has roots at \(x = -1, 4\).
x1 <- -1
x2 <- 4
int_g <- integrate(g, x1, x2)
int_h <- integrate(h, x1, x2)
(area <- int_g[1]$value - int_h[1]$value)
## [1] 20.83333
Let \(x\) be the number of flat irons per order, and \(n\) be the number of orders. This means that \(nx = 110\). Let’s also introduce the below functions for the cost of storage (\(S(x)\)) and ordering \(\Gamma(X)\).
\[\begin{aligned} S(x) = 3.75x\newline \Gamma(x) = 8.25\frac{110}{x} \end{aligned}\]Let the total cost function be \(C(x) = S(x) + \Gamma(x) = 3.75x + \frac{907.5}{x}\). To find a minimal cost as a function of flat irons ordered, we’ll need to find where \(C'(x) = 0\)
\[\begin{aligned} C'(x) = 3.75 - \frac{907.5}{x^2}\newline 0 = 3.75 - \frac{907.5}{x^2}\newline 3.75 = \frac{907.5}{x^2} x = 16.02 \end{aligned}\]Now, plugging in for \(n\), rounding x to 16
\[\begin{aligned} nx = 110\newline n(16) = 110 n = 6.875 \end{aligned}\]First, let’s choose our \(u\) and \(v\) parts of our integral. Let
\[\begin{aligned} u = \ln(9x)\newline v = \frac{x^7}{7}\newline \,du = \frac{9}{x}\,dx \end{aligned}\]We can plug into the integration by parts formula:
\[\begin{aligned} \int u\,dv = uv - \int v\,du\newline = \ln(9x)\frac{x^7}{7} - \int \frac{x^6}{7}\,dx\newline = \ln(9x)\frac{x^7}{7} - \frac{x^7}{49} + C \end{aligned}\]We can check if a function over a given integral is a probability density by integrating the function over that integral. If the expression evaluates to 1, we have a probability density function:
f <- function(x){
return(1 / (6 * x))
}
# Now let's integrate over our interval
(i <- integrate(f, 1, exp(6)))
## 1 with absolute error < 9.3e-05
Since our integral evaluates to 1, our function \(f(x) = \frac{1}{6x}\) is a PDF on the interval \([1, e^6]\)