Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
License: OTHER
Image: ubuntu2004

licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Prerequisites:
Intro to Sage
Graphing and Solving Equations
Tangent Lines
Differentiation
Last time we saw that the slope of the line tangent to a function at the point is equal to .
Since every point on the graph of has a different tangent line, the slope of the tangent line may change. To keep track of these slopes, we define a new function, called the "derivative" of .
In other words, the derivative of the function , denoted or , gives the slope of the line tangent to at . Replacing with in the above limit results in the following formula for the derivative:
Note: The slope of the tangent line is also the (instantaneous) rate of change of the function. So you can think of the derivative as giving the rate of change of .
In this lab, we will learn how to use Sage to calculate derivatives (called "differentiation"), and we will look at graphs of the derivative function.
Calculating the Derivative Function
To calculate the derivative of a function in Sage, we use the derivative command. This command requires two arguments: (1) a function name or an expression and (2) the variable with respect to which the derivative is to be calculated.
Example 1
Find the derivative of .
We could do this using limits:
However, instead of using limits it will be easier to use the derivative command:
You can also define a function first, and use the function name in the derivative command.
Whichever way we do it, we see that .
Example 2
Find the derivative of .
We see .
Calculating a Particular Value of the Derivative
There are two ways to calculate the value of the derivative at a particular point.
Give the derivative function a name, and then use it to calculate the particular value.
Add (x=particular value) in parentheses after the derivative command.
Example 3
Suppose we want to calculate when .
Method 1: Name the derivative function. Sage does not allow the name , so I like to use df(x) [d for derivative].
Now that I have defined my derivative function df(x), I can use it to evaluate .
Sage tells me that .
Method 2: Add (x=3) after the derivative command:
Notice that we get the same answer: .
Caution: The (x=3) must come after the closing parenthesis of the derivative command. There is no place for the 3 within the derivative command. You must substitute 3 after finding the derivative, either by naming the derivative function or by putting (x=3) afterwards.
Example 4
Find (using the same from above).
Method 1: Give the derivative a name, such as dg. Then we simply compute dg(5).
Use the N() command if you want a numerical approximation:
So (notice the scientific notation).
Method 2: Add the particular value after the derivative command:
Of course, we get the same answer as we got from method 1.
Example 5
Find .
If you already have a dg function (method 1), then just compute dg(-3).
Thus, .
If you are using method 2, then compute the derivative again:
If you have many particular values to calculate, method 1 is more efficient. If you need only one particular value, then method 2 involves less typing.
Personally, I prefer method 1. I think method 1 more clearly shows what you are doing.
Derivatives with Other Variables
Sage is able to handle derivative when other variables are involved. All variables other than the variable of differentiation (the variable after the comma in the derivative command) are treated as constants (unspecified numbers).
Example 6
Find the derivative of . [It's implied that the derivative is with respect to , since the function is defined as a function of .]
So .
Of course, if we take the derivative with respect to , , or we will get a different answer. [This is awkward, since F is written as a function of . This is not a normal Calculus 1 question, but Sage is able to deal with it.]
Applied Example - Velocity
The rate of change of position with respect to time (called velocity) is the derivative of the position function.
Example 7
The position (in feet) of an object moving in a straight line after minutes is given by the function .
How fast is the object travelling at minutes?
The objects's velocity is ft/min.
You could also use method 2 (note that we have t=10, not x=10):
Higher-Order Derivatives
The second derivative of , denoted or , is the derivative of . In other words, or .
Similarly, the third derivative of , denoted or, is the derivative of .
After the third derivative, we stop using primes. For example, the fourth derivative is denoted and the tenth derivative is denoted .
If you want the second, third, etc. derivative in Sage, you need to add one more argument to the derivative command.
Example 8
Here are some second derivatives (using the same , , and from above):
Example 9
Here are some higher-order derivatives (same , , and ):
Example 10
Find .
Method 1:
Notice the scientific notation again:
Method 2:
Applied Example - Acceleration
Acceleration is the rate of change of velocity. In other words, acceleration is the second derivative of the position function.
Example 11
The position (in feet) of an object moving in a straight line after minutes is given by the function .
What is the object's acceleration at minutes?
The acceleration is ft/min/min = ft/min.
Graphs of Derivatives
We are going to graph a function and its derivative and compare.
Example 12
Let's start with a simple example and look at the graphs of and its derivative.
Notice:
When the original function is increasing, the derivative is positive.
When is decreasing, is negative.
has a local minimum at , and .
Caution: There is no relationship between the direction (increasing/decreasing) of and the direction of . The relationship is between the direction of and the sign (positive/negative) of .
Example 13
Now let's look at and its derivative.
Again we observe the same relationship:
When the original function is increasing, the derivative is positive.
When is decreasing, is negative.
When has a local minimum or maximum, is .
Also observe the following:
When is concave up, is increasing.
When is concave down, is decreasing.
When has an inflection point, has a local minimum or maximum.
Tangent Lines
Last time we used limits to find the slopes of tangent lines. Now we can use the derivative to find the slope.
In general, the tangent line to at has equation .
Example 14
Suppose we want the tangent line to the function when .
An equation for the line is .
Applied Example - Population Growth
Given a function that gives the population at time , the derivative gives you the rate of change of the population - how quickly the population is increasing (or decreasing).
Example 15
The population of Sageville years after its founding is modelled by the equation
At what rate was the population increasing 100 years after its founding?
The population is growing at a rate of approximately 7 persons per year 100 years after the founding of Sageville.
Note: A common mistake here is to claim that the population is growing at a rate of "7%," but this growth rate is not a percentage. The correct units are "persons/year." In fact, 7 persons is less than 0.2% of the population at this time.
Example 16
Find a formula for the tangent line of above at . Graph and its tangent line.
Example 17
Calculate for the population model above. What does this quantity represent in this context?
.
This means that the rate of increase of the population is declining at a rate of about persons/year per year 100 years after the founding of Sageville.
Although the population is still increasing , its not increasing as rapidly as before .