Last time we saw that the slope of the line tangent to a function $f(x)$ at the point $(x_0,f(x_0))$ is equal to $\displaystyle\lim_{h\to 0}\frac{f(x_0+h)-f(x_0)}{h}$.
Since every point on the graph of $f$ 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 $f$.
In other words, the derivative of the function $f(x)$, denoted $f'(x)$ or $\frac{d}{dx}f(x)$, gives the slope of the line tangent to $f$ at $x$. Replacing $x_0$ with $x$ in the above limit results in the following formula for the derivative: $f'(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
Note: The slope of the tangent line is also the (instantaneous) rate of change of the function. So you can think of the derivative $f'$ as giving the rate of change of $f$.
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.
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.
Find the derivative of $f(x)=x^2$.
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 $f'(x)=2x$.
Find the derivative of $g(x)=x^3e^{-x^2}$.
We see $g'(x)=-2x^4e^{-x^2}+3x^2e^{-x^2}$.
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.
Suppose we want to calculate $f'(3)$ when $f(x)=x^2$.
Method 1: Name the derivative function. Sage does not allow the name $f'(x)$, 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 $f'(3)$.
Sage tells me that $f'(3)=6$.
Method 2: Add (x=3) after the derivative command:
Notice that we get the same answer: $f'(3)=6$.
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.
Find $g'(5)$ (using the same $g(x)$ 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 $g'(5)=-1175e^{-25}\approx-1.63\times10^{-8}=-0.0000000163$ (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.
Find $g'(-3)$.
If you already have a dg function (method 1), then just compute dg(-3).
Thus, $g'(-3)\approx -0.016660$.
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.
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).
Find the derivative of $F(x)=ax^2+bx+c$. [It's implied that the derivative is with respect to $x$, since the function is defined as a function of $x$.]
So $F'(x)=2ax+b$.
Of course, if we take the derivative with respect to $a$, $b$, or $c$ we will get a different answer. [This is awkward, since F is written as a function of $x$. This is not a normal Calculus 1 question, but Sage is able to deal with it.]
The rate of change of position with respect to time (called velocity) is the derivative of the position function.
The position (in feet) of an object moving in a straight line after $t$ minutes is given by the function $p(t)=-3t^2+40t+5$.
How fast is the object travelling at $t=10$ minutes?
The objects's velocity is $-20$ ft/min.
You could also use method 2 (note that we have t=10, not x=10):
The second derivative of $f(x)$, denoted $f''(x)$ or $\frac{d^2}{dx^2}f(x)$, is the derivative of $f'(x)$. In other words, $f''(x)=(f')'(x)$ or $\frac{d^2}{dx^2}f(x)=\frac{d}{dx}\left(\frac{d}{dx}f(x)\right)$.
Similarly, the third derivative of $f(x)$, denoted $f'''(x)$ or$\frac{d^3}{dx^3}f(x)$, is the derivative of $f''(x)$.
After the third derivative, we stop using primes. For example, the fourth derivative is denoted $f^{(4)}(x)=\frac{d^4}{dx^4}f(x)$ and the tenth derivative is denoted $f^{(10)}(x)=\frac{d^{10}}{dx^{10}}f(x)$.
If you want the second, third, etc. derivative in Sage, you need to add one more argument to the derivative command.
Here are some second derivatives (using the same $f$, $g$, and $F$ from above):
$f''(x)=2$
$g''(x)=4 \, x^{5} e^{\left(-x^{2}\right)} - 14 \, x^{3} e^{\left(-x^{2}\right)} + 6 \, x e^{\left(-x^{2}\right)}$
$F''(x)=2a$
Here are some higher-order derivatives (same $f$, $g$, and $F$):
$f'''(x)=0$
$g^{(5)}(x)=-32 \, x^{8} e^{\left(-x^{2}\right)} + 400 \, x^{6} e^{\left(-x^{2}\right)} - 1320 \, x^{4} e^{\left(-x^{2}\right)} + 1140 \, x^{2} e^{\left(-x^{2}\right)} - 120 \, e^{\left(-x^{2}\right)}$
$F^{(4)}(x)=0$
Find $g^{(10)}(7)$.
Method 1:
Notice the scientific notation again: $g^{(10)}(7)\approx 2.17\times 10^{-8}=0.0000000217.$
Method 2:
Acceleration is the rate of change of velocity. In other words, acceleration is the second derivative of the position function.
The position (in feet) of an object moving in a straight line after $t$ minutes is given by the function $p(t)=-3t^2+40t+5$.
What is the object's acceleration at $t=10$ minutes?
The acceleration is $-6$ ft/min/min = $-6$ ft/min$^2$.
We are going to graph a function and its derivative and compare.
Let's start with a simple example and look at the graphs of $f(x)=x^2$ and its derivative.
Notice:
Caution: There is no relationship between the direction (increasing/decreasing) of $f$ and the direction of $f'$. The relationship is between the direction of $f$ and the sign (positive/negative) of $f'$.
Now let's look at $g(x)=x^3e^{-x^2}$ and its derivative.
Again we observe the same relationship:
Also observe the following:
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 $f$ at $x = x_0$ has equation $y=f(x_0)+f'(x_0)(x-x_0)$.
Suppose we want the tangent line to the function $g(x)=x^3e^{-x^2}$ when $x=2$.
An equation for the line is $y=g(2)+g'(2)(x-2)$.
Given a function $P(t)$ that gives the population at time $t$, the derivative $P'(t)$ gives you the rate of change of the population - how quickly the population is increasing (or decreasing).
The population $P$ of Sageville $t$ years after its founding is modelled by the equation $\displaystyle P(t)=\frac{4000}{1+399e^{-0.1t}}.$
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.
Find a formula for the tangent line of $P(t)$ above at $t=100$. Graph $P$ and its tangent line.
Calculate $P''(100)$ for the population model above. What does this quantity represent in this context?
$P''(100)\approx -0.67$.
This means that the rate of increase of the population is declining at a rate of about $0.67$ persons/year per year 100 years after the founding of Sageville.
Although the population is still increasing $(P'(100)>0)$, its not increasing as rapidly as before $(P''(100)<0)$.