The average speed of a moving object over some time interval is the distance
between positions divided by the time it took to get from one position to the
next. More generally, the average rate of change of a function of time is the
change in the value of the function divided by the length of the time interval.
# Code for weird_function(), which will be used in the following exercise:defweird_function():pieces=[sin(x),cos(x),arctan(x),ln(x),sqrt(x),exp(x)]f(x)=prod([choice(pieces)foriinsrange(5)])+prod([choice(pieces)foriinsrange(5)])returnf
Exercise 1. Evaluate the cell in your turn-in sheet that contains the function
weird_function() and run the command h(x)=weird_function() to create a
random function called h(x).
Exercise 2. Compute the average rate of change of h(x) between x=3.5 and
We know the average rate of change of the function between x=3.5 and
x=5.5. Now, we want its rate of change at x=3.5.
Exercise 3. Create a list of average rates of change for h(x) for Δx values of
1, 0.1, 0.01, and 0.001. That is find the average rate of change between x=3.5 and x+Δx. (You can do this by hand or use a loop.) Use the result
to estimate the function’s rate of change at x=3.5. Why do you think the
number you gave is the rate of change at that value of x? Please make sure you get decimal answers.
At this point, you might be wondering why we bother with different values
of Δx at all. Why not just pick a small value of Δx and always use that to
compute rates of change? The answer won’t be mathematically precise, but
real-world measurements always have some error anyway. The following series
of exercises will explore this question.
Exercise 5. Find the average rates of change for the function f(t)=t3−3t2+4t+1
at t=1 using 1, 0.1, 0.01, and 0.001 as your values of Δt. Then, estimate the
function's rate of change at t=1. Feel free to use more Δt values if you want.
Exercise 7. Drawing on your results, briefly explain why limits are necessary
when computing derivatives. Why don't we just pick a small value of Δt and
always use that?
In [ ]:
#There needs to be limits when computing derivatives because it allows us to get as close to the value in order to be more percise.
Symbolic Calculations in Sage
One of Sage’s most powerful features is its ability to do symbolic computations
– calculations with variables rather than numbers. Such calculations require
you to use a particular kind of variable called a symbolic variable. Symbolic
variables can be manipulated algebraically without having numerical values.
The variable x is a built-in symbolic variable.
Exercise 8. Compute x3x7.
Exercise 9. Find the type of x.
The variable x is a built-in symbolic variable. To use other symbolic variables,
like N or P, you'll need to create them. This is called declaring the
variables and is done using the var function. This function takes a string of
variable names, separated by commas, as input and generates the appropriate
Note that Sage assumes that a=0.
Symbolic variables don't have to be single letters.
3*rabbits + 2*sheep
Once a symbolic variable has been declared, you can use it in subsequent
calculations without re-declaring it until you close your worksheet.
The command factor allows you to factor polynomials.
(a + 3)*(a + 2)
Exercise 10. Factor x2+7x+6.
(x + 6)*(x + 1)
Exercise 11. Factor k2−5k+6.
(k - 2)*(k - 3)
Plotting uses symbolic variables, so if you want to plot a function of a variable
other than x, you have to declare it before using it.
Exercise 12. Plot the function f(n)=2n using n as the independent variable, for values of n between -30 and 30.
You don't need to define the function before plotting it.
Once you assign a numeric value to a symbolic variable, it’s no longer a
symbolic variable. Instead, it's now a number. A common plotting error results
from assigning a value to some variable, usually x, and later using that variable
in a plot. The tell-tale symptom of this problem is a graph consisting of one or
more horizontal lines. Execute the cell below to see the issue.
Exercise 13. Why is the horizontal line y=2 rather than some other value of
In [ ]:
#y=2^3 which is y=8 being plot on the y axis it is running the number instead of the symbolic varibale 5
To fix this problem, just declare x to be a symbolic variable again.