Class 25

Between Class Sessions - Prep for Day 25

Please spend around 2 hours working between class sessions, focusing on the tasks below. Use any extra time to complete KnewtonAlta assignments and/or work on Project tasks.

Pick something from your prep today that you can share with your group in class. It might be something new that you learned. It might be questions you have that are still unanswered, or a question along with what helped you eventually answer it. It might be something tricky that you solved. It might be a review topic that helped you remember something. It might be a conversation you had with AI that was helpful. You will have a chance to share this with your peers during class. Come ready to articulate your thinking and questions.

Preparation

(1) Extrema Vocabulary

Answer as many of the questions from Derivative Relationships Fill in the Blank as possible. Use sections 4.3 and 4.5 from the OpenStax Calculus Volume 1 as a resource.

(2) Writing Equations (still practicing)

Write an equation in one variable for the described quantity in each story below.

  1. A farmer has 2400 feet of fencing to build a fence creating a rectangular corral (or pen) for some of the animals. Write an equation in one variable for the area of the rectangular corral. (Our goal will be to build the corral with maximum area.)

  2. A different farmer also has 2400 feet of fencing to build a fence creating a rectangular corral, but she plans to use the wall of a long group of buildings as one of the sides of the rectangular corral. Write an equation in one variable for the area of the rectangular corral. (Our goal will be to build the corral with maximum area.)

  3. A company is building square-bottomed boxes with no tops. The material for the bottom costs $2 per cm\(^2\) and the material for the sides costs $1 per cm\(^2\). The company plans to charge $96 for one box. Write an equation in one variable for the volume of the box. (Our goal will be to build a box with maximum volume.)

After you have written down each function, open R and plot each function to visually identify where the maximum of each function occurs.

(3) Making Connections

Open Project 2 instructions.

  • Consider the model \(f_5\). Review your computations to obtain the loglikelihood function (or complete the computations now). The answer is provided to you in the Task 1 Instructions. Your job is to perform the needed computations and include explanations of each of the steps.
    • Note: This is part of the required work for Project 2 Task 1.
  • Now compute the first and second derivative of this loglikelihood function.
    • Note: This is part of the required work for Project 2 Task 2.
  • Adapt the following code (from class today) to plot this loglikelihood function.
#clear the environment
rm(list=ls())
#load the library
library(data4led)
#read in the data set
bulb <- led_bulb(1,seed=123) #Remember to use your assigned seed!

# Here is our Data.
t <- bulb$hours
y <- bulb$percent_intensity

#define the loglikelihood function
l <- function(p,t,y){
  44*log(1/sqrt(2*pi)) - (1/2)*sum((y-100-p*t)^2)
}

#create a list of inputs for our plot of the loglikelihood function
a1 <- seq(-0.005,0.005,1e-5)
#use those inputs to calculate outputs for our plot of the loglikelihood function
Y <- as.vector(lapply(a1,FUN=l,t=t,y=y))

#plot the loglikelihood function
plot(a1,Y,type='l')
  • Make a guess for what you think is the best value for \(a_1\). How did you decide on that value?
  • Using what you learned in the reading, how might you find the best value for \(a_1\) rather than just estimating from the graph?
    • Note: This is part of the required work for Project 2 Task 3. We will continue to discuss these concepts next week in class.

Regular Reminders

Skill Practice (KA Homework)

  • If you have not done so already, complete the other derivative rule assignments
    • 2 – Derivative Rules (Power Function, Sum/Difference, Constant Multiple)
    • 2 – Derivative Rules (Product and Quotient)
    • 2 – Derivative Rules (Function Composition) - the Chain Rule
    • 2 – Linearization
    • 2 – Partial Derivatives

Applied Practice (Project Work)

  • Continue working on Project 2 Task 2

During Class

Brain Gains

  1. A box with a square bottom and no top is to be built with 6 square feet of cardboard (so you need material for 5 sides). Write a function that gives the volume of the box as a function of the side length of the square.
Solution

The base has area \(x^2\). Letting \(h\) be the height of the box, the volume of the box is \(V(x,h) = x^2h\). Each the sides has area \(4xh\), which means the total area of 6 must satistify \(6 = x^2+4xh\). From here we can get \(h\) by itself as \(h =\frac{6-x^2}{4x}\). This means the volume is \[ \begin{aligned} V(x) &= x^2 h \\ &= x^2 \, \frac{6 - x^2}{4x} \\ &= \frac{1}{4} x (6 - x^2). \end{aligned} \]

  1. Use R to plot the function above, and then guess the maximum possible volume along with the dimensions that correspond to this volume.
Solution

We graph \(V(x) = x^2 h = x^2 \cdot \frac{6 - x^2}{4x}\) (using \(h\) from Question 1). The peak lies inside the domain \(0 < x < \sqrt{6}\) (so the side length is positive and the height stays positive).

V <- function(x){x^2*((6-x^2)/(4*x))}

#Plot V across its domain.
x <- seq(0, 4, 0.01)
plot(x, V(x), type = "l")

#The peak looks to be a bit less than x = 1.5.
abline(v = sqrt(2))

From the plot, the maximum volume is around \(1.4\) cubic feet at a side length near \(x = \sqrt{2} \approx 1.414\) feet. We’ll pin down that value exactly with the derivative in Question 3.

  1. Compute the derivative of the function above, and use it to find the maximum possible volume.

Group Meeting

Start by giving each person a moment to share what they chose to prepare for class. Help each other address any questions. When each person has had a chance to share, move on the other activities.

Activity - Comparing Solutions

Our goal today is to dig into the derivative relationships and associated vocabulary. Your assignment before class was to fill in as many of the blanks, as possible, from DerivativeRelationship_FillBlank.pdf. Compare your answers, discuss any questions, and have a scribe write your solutions on the board (so you can compare with other groups).

You may need some of definitions, theorem, or tests below as you complete the next activity. Take a moment to open each item and review it.

Theorems - Tests - Definitions

Intermediate Value Theorem (IVT)

If \(f(x)\) is a continuous function on a closed interval \([a, b]\), where \(f(a) \neq f(b)\), and \(y_0\) is any \(y\)-value strictly between \(f(a)\) and \(f(b)\), then \(y_0 = f(x_0)\) for some \(x\)-value, \(x_0\), in \([a, b]\).

Note: While there is a rigorous mathematical definition for what it means to be a continuous function, for our purposes the following concept with suffice, a function is continuous on an interval if the graph of that function can be traced with a pencil without lifting the pencil from the page.

Rolle’s Theorem

Let \(f\) be a continuous function over the closed interval \([ a, b ]\) and differentiable over the open interval \(( a, b )\) such that \(f(a) = f(b)\). Then there exists at least one \(c \in ( a, b )\) such that \(f'(c) = 0\).

Extreme Value Theorem

If \(f\) is a continuous function over the closed, bounded interval \([a, b]\), then there is a point in \([a, b]\) at which \(f\) has an absolute maximum over \([a, b]\) and there is a point in \([a, b]\) at which \(f\) has an absolute minimum over \([a, b]\).

First Derivative Test

Suppose that \(f\) is a continuous function over an interval \(I\) containing a critical point \(c\). If \(f\) is differentiable over \(I\), except possibly at point \(c\), then \(f(c)\) satisfies one of the following descriptions:

  • If \(f'\) changes sign from positive when \(x < c\) to negative when \(x > c\), then \(f(c)\) is a local maximum of \(f\).
  • If \(f'\) changes sign from negative when \(x < c\) to positive when \(x > c\), then \(f(c)\) is a local minimum of \(f\).
  • If \(f'\) has the same sign for \(x < c\) and \(x > c\), then \(f(c)\) is neither a local maximum nor a local minimum of \(f\).
Second Derivative Test

Suppose that \(f'(c) = 0\), \(f''\) is continuous over an interval containing \(c\).

  • If \(f''(c) > 0\), then \(f\) has a local minimum at \(x=c\).
  • If \(f''(c) < 0\), then \(f\) has a local maximum at \(x=c\).
  • If \(f''(c) = 0\), then the test is inconclusive.
Definition: Increasing (reminder)

We say that a function \(f\) is increasing on the interval \(I\) if for all \(x_1, x_2 \in I\), \(f(x_1) \leq f(x_2)\) when \(x_1 < x_2\).

Definition: Decreasing (reminder)

We say that a function \(f\) is decreasing on the interval \(I\) if for all \(x_1, x_2 \in I\), \(f(x_1) \geq f(x_2)\) when \(x_1 < x_2\).

Definition: Concavity

Let \(f\) be a function that is differentiable over an open interval \(I\).
If \(f'\) is increasing over \(I\), we say \(f\) is concave up over \(I\).
If \(f'\) is decreasing over \(I\), we say \(f\) is concave down over \(I\).

Let \(f\) be a function that is twice differentiable of an interval \(I\).

  • If \(f''(x) > 0\) for all \(x \in I\), then \(f\) is concave up over \(I\).
  • If \(f''(x) < 0\) for all \(x \in I\), then \(f\) is concave down over \(I\).
Definition: Absolute Maximum

Let \(f\) be a function defined over an interval \(I\) and let \(c \in I\). We say \(f\) has an absolute maximum on \(I\) at \(c\) if \(f(c) \geq f(x)\) for all \(x \in I\).

Definition: Absolute Minimum

Let \(f\) be a function defined over an interval \(I\) and let \(c \in I\). We say \(f\) has an absolute minimum on \(I\) at \(c\) if \(f(c) \leq f(x)\) for all \(x \in I\).

Definition: Local Maximum

A function \(f\) has an local maximum at \(c\) if there exists an open interval \(I\) containing \(c\) such that \(I\) is contained in the domain of \(f\) and \(f(c) \geq f(x)\) for all \(x \in I\).

Definition: Local Minimum

A function \(f\) has an local minimum at \(c\) if there exists an open interval \(I\) containing \(c\) such that \(I\) is contained in the domain of \(f\) and \(f(c) \leq f(x)\) for all \(x \in I\).

Definition: Critical Point (or critical value)

We say that \(x=c\) is a critical point of \(f\) if \(f'(c) = 0\) or \(f'(c)\) is undefined.

Definition: Inflection Point

If \(f\) is continuous at \(x=a\) and \(f\) changes concavity at \(x=a\), the point \((a, f(a))\) is an inflection point of \(f\).

Activity - Constructing Examples

To help us understand derivative relationships and associated vocabulary, let’s create sketches that illustrate the concepts. At the chalk boards, take turns providing a rough sketch of a function with the properties listed (also sketch the derivative and/or second derivative if this helps you make sense of the properties). Number your graphs, keep them small-ish, and try to fill your board with examples that we can compare with others. Use the information above for reference.

  1. \(f\) is increasing and concave up for all \(x\).

  2. \(f\) so that \(f'(x) > 0\) and \(f''(x)<0\) for all \(x\).

  3. \(f\) has an inflection point at \(x=4\).

  4. \(f\) has a horizontal tangent line when \(x=3\).

  5. \(f\) so that \(f'=0\) for all \(x\).

  6. \(f\) so that \(f'=0\) and \(f''>0\) at \(x=-2\).

  7. \(f\) is decreasing and concave down on the interval \((-3,5)\).

  8. \(f\) so that \(f'\) has at least one change of sign and is always defined.

  9. \(f\) so that \(f'=0\) and \(f''<0\) at \(x=1\).

  10. \(f\) so that -\(f\) is concave down everywhere.

When you finish, work on this worksheet together (remember to take turns).

Activity - Visualizing \(f\), \(f'\), \(f''\) (with R feedback)

Download the worksheet and run it in Positron: visualizing_derivatives.qmd

The worksheet walks you through five functions (\(x^2\), \(x^3\), \(x^4\), \(e^x\), \(\ln x\)) with ready-to-run R cells that overlay \(f\), \(f'\), and \(f''\) on shared axes after you’ve sketched each one.

Draw first, then run the code. The whole point is to predict the shape of \(f'\) and \(f''\) from the shape of \(f\) — running the cells before sketching defeats the exercise. Open the file in Positron, follow the instructions in the document, and run each step’s cell only after you’ve put pencil to paper.

Class Discussion

ElvesRUs Extended

Last time we worked on a ElvesRUs loglikelihood (full problem statement included below). We found the loglikelihood of the errors, rewrote the function using the properties of logs and sums, and found the first partials of the loglikelihood function.

You have been given a list of data for 50 ElvesRUs employees, \((t_i, c_i)\), were \(t_i\) is the number of years working at ElvesRUs and \(c_i\) is the salary for the \(i^{\text{th}}\) employee. The salary (platinum coins per year) for an employee at ElvesRUs can be modeled by \(f(t;A,b,k)=Ae^{bt}+k,\) where \(t\) is the number of years an elf has been working at ElvesRUs. Assume the residuals (errors) are independent and normally distributed (with mean of 0 and standard deviation of 1), which means we’re assuming the probability model for the residuals is \(p(r) = \frac{1}{\sqrt{2\pi}}e^{-\frac{r^2}{2}}\).

Today let’s compute the following second partial derivatives: \(\frac{\partial^2\ell}{\partial A^2}\), \(\frac{\partial^2 \ell}{\partial b \partial A}\), \(\frac{\partial^2 \ell}{\partial k \partial A}\), \(\frac{\partial^2 \ell}{\partial A \partial b}\), \(\frac{\partial^2\ell}{\partial b^2}\), and \(\frac{\partial^2 \ell}{\partial k \partial b}\) Is this all the partials? (No!) Turn back in your notes (or use the following link) to get the first partials. ElvesRUs loglikelihood derivatives (PDF)

Answers
  • \(\frac{\partial^2\ell}{\partial A^2} = \sum_{i=1}^{50} -e^{2bt_i}\)
  • Use the fact that (for nice function) the mixed partials will be the same to check \(\frac{\partial^2 \ell}{\partial b \partial A}\).
  • \(\frac{\partial^2 \ell}{\partial k \partial A} = \sum_{i=1}^{50} -e^{bt_i}\)
  • Use the fact that (for nice function) the mixed partials will be the same to check \(\frac{\partial^2 \ell}{\partial A \partial b}\).
  • \(\frac{\partial^2\ell}{\partial b^2} = \sum_{i=1}^{50} At_i^2(c_i -k)e^{bt_i} - 2t_i^2A^2e^{2bt_i}\)
  • \(\frac{\partial^2 \ell}{\partial k \partial b} = \sum_{i=1}^{50} -At_ie^{bt_i}\)

Source: Class.25 on byuimath.com