Background

The purpose of the assignment was to explore the fundamentals of Calculus in R.


Exercise 1

Use integration by substitution to solve ∫ \(4e^{-7x} dx\).

We apply u-substituton and unwind the chain rule.

To start, let’s define u: \(u = -7x\)

From this we take the derivative of u with respect to x and derive: \(du/dx = -7\) –> \(dx = -1/7 du\)

We substitute our u’s back into the integral, integrate, and back-substitute:

\(-4/7 ∫ e^u du\). –> \(-4/7 e^u\) –> \(-4/7 e^{-7x}\)

Note: the anti-Derivative of e^x is simply e^x + C (a constant).

And voila! We have a solution: \(-4/7 e^{-7x}\).

In solving this exercise I referred to Khan Academy.

Exercise 2

Biologists are treating a pond with bacteria. The level of contamination is changing at a rate of \(dN/dt = -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 day 1 was 6530 bacteria per cubic centimeter.

This is an anti-Derivative problem with a Power Rule component.

\(dN/dt = -3150/t^4 -220\) can be rewritten as \(dN/dt = -3150t^{-4} -220\) and thus we apply the Power Rule to the 1st term:

\(x^n dx\) –> \(1/(n+1) * (x^{n+1})\)

In our case n = -4 and we can solve for this 1st term as:

\(-3150 ∫ t^{-4} dt\) –> \(-3150/{-3} * t^{-3}\) –> \(1050 t^{-3}\)

The 2nd term is a simpler anti-Derivative:

\(-220 dt\) –> \(-220t\)

And with the whole derivation put back together, we have to account for a constant as our 3rd term, thus giving:

\(1050 t^{-3} - 220t + C\)

Fortunately for us, we were provided that after day 1 there was 6530 bacteria, and thus we can substitute to solve for C:

\(6530 = 1050 * 1^{-3} -220(1) + C\) –> \(C = 6530 - 1050 + 220\)

\(C = 5700\)

Providing us the following function for N(t): \(1050 t^{-3} - 220t + 5700\)

In solving this exercise I referred to socratic.org.

Exercise 3

Find the total area of the red rectangles in the figure on the assignment hand out, where the equation of the line is f(x) = 2x - 9.

For this problem I elected to compare the solutions between (2) different methods:

  1. sum of rectangle areas, and

  2. area under line

#method 1: sum areas of rectangles

rect_1 <- (5.5 - 4.5) * 1
rect_2 <- (6.5 - 5.5) * 3
rect_3 <- (7.5 - 6.5) * 5
rect_4 <- (8.5 - 7.5) * 7

sum1 <- rect_1 + rect_2 + rect_3 + rect_4

#method 2: area under line
library(stats)

f <- function(x){
  (2 * x) - 9
  }
sum2 <- integrate(f, lower=4.5, upper=8.5)

#compare solutions
sum1
## [1] 16
sum2
## 16 with absolute error < 1.8e-13

We note identical solutions and confirm that method 1 and 2 both work and provide a solution of area = 16.

Exercise 4

Find the area of the region bound by the graphs of the given equations: \(y = x^2 -2x -2\), \(y = x + 2\).

Prior to calculating anything in R, I took a sheet of graph paper and drew each function up until their points of intersection to (1) visualize the problem and (2) determine the upper and lower bounds.

Based on the guidance of the reference (provided below), I realized that we had to subtract the lower function (\(x^2 - 2x -2\)) from the upper function (\(x + 2\)) and integrate from our lower point of intersection (\(x = -1\)) through our upper point of intersection (\(x = 4\)).

Subtracting functions, we derive the following:

\((x + 2) - (x^2 - 2x - 2)\) –> \(-x^2 + 3x + 4\)

And were able to calculate the area:

f2 <- function(x){
  -x^2 + (3 * x) + 4
  }
area <- integrate(f2, lower=-1, upper=4)
area
## 20.83333 with absolute error < 2.3e-13

Utilizing by hand calculations / visualization and R’s built in integrate() and function() functions, we derive our solution as area = 20.83333.

In solving this exercise I referred to tutorial.math.lamar.edu.

Exercise 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 cost.

\(cost_{inventory} = cost_{order} + cost_{storage}\)

  • \(cost_{order} = 8.25 * x\) #where we’ll take ‘x’ to be the number of orders
  • \(cost_{storage} = 3.75 * l\) #where we’ll take ‘l’ to be the lot size

From this, we define ‘l’ in terms or the number of irons ordered through the year and divide it by the number of orders placed, assuming that there’s no need to store more than each order size (ie. orders in batches of 20 mean that we at most need storage for 20). From this point we re-define ‘l’ and the \(cost_{storage}\) equation:

  • \(cost_{storage} = 3.75 * (110/x)\)

Now we can back-substitute and take the derivative of the corresponding \(cost_{inventory}\) equation to find the minimum inventory cost:

\(cost_{inventory} = cost_{order} + cost_{storage}\)

\(cost_{inventory} = 8.25 * x + 3.75 * (110/x)\)

\(cost_{inventory} = 8.25 * x + 412.5 * x^{-1}\)

Taking the derivative, we arrive at:

\(cost_{inventory} = 8.25 - 412.5 * x^{-2}\)

Substituting 0 for \(cost_{inventory}\) so that we’re calculating for the min:

\(0 = 8.25 - 412.5 * x^{-2}\)

And re-structuring our equations, we arrive at:

\(x^{-2} = 8.25 / 412.5\) \(x^{-2} = 1 / 50\) \(x^{2} = 50\)

And then taking the square root:

\(x = 7.071\)

And rounding it down to the nearest whole number, we get:

\(x = 7\)

Back substituting this, we have:

\(l = 110/7\)

\(l = 15.714\)

And rounding up to the nearest whole number, we get:

\(l = 16\)

And thus we arrive at our inventory cost by substituting our variable values:

\(cost_{inventory} = (8.25 * 7) + (3.75 * 16)\)

\(cost_{inventory} = 117.75\)

To sum it all up, placing 7 orders and maintaining a lot size of 16 would bring our inventory cost down to $117.75 (a minimum value).

Exercise 6

Use integration by parts to solve ∫ \(ln(9x) x^6 dx\).

As a refresher, integration by parts is performed as: ∫ uv dx = u ∫v dx - ∫ u’ (∫v dx) dx.

We first define:

  1. \(u = ln(9x)\) and u’ as the derivative \(u' = 1/9x\).
  2. \(v = x^6\) and \(∫v = 1/7 x^7\)

We then substitute our values into the equation defined above:

\(ln(9x) ∫x^6 dx - ∫1/9x^{-1}(∫x^6)\)

We perform our first integration:

\(ln(9x) ∫x^6 dx - ∫1/9x^{-1}(∫x^6dx)dx\)

We perform our second integration:

\(1/7x^7ln(9x) - (1/7)(1/9)(∫x^{7-1})\)

And we arrive at our solution:

\(1/7x^7(ln(9x) - 1/63) + C\)

In solving this exercise I referred to mathisfun.com.

Exercise 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) = 1/6x.

For f(x) to be a probability function, it would need to satisfy the following conditions:

  1. f(x) >= 0 for all x, and
  2. ∫f(x)dx = 1 when integrated from -inf to inf.

Now, let’s explore:

f3 <- function(x){
  1 / (6 * x)
  }
area <- integrate(f3, lower=1, upper=exp(6))
area
## 1 with absolute error < 9.3e-05

From the result of the above integration it appears that f(x) satisfies both conditions outlined above and thus f(x) is a PDF on the provided interval.

In solving this exercise I referred to math24.net.