CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.
CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.
Aaron Tresham Calculus Materials - Feb 2018 snapshot
licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Prerequisites:
Intro to Sage
Review of Sage
For those of you who had a Calculus 1 lab with me last semester, you are already familiar with Sage. This worksheet is a quick review of some of the key features we covered last semester.
If you have not used Sage before, I recommend working through the Calc 1 lab "Intro to Sage." Then return to this worksheet.
Graphing
You graph a function in Sage using the "plot" command.
Example 1
Graph .
Remember, every multiplication must be explicit in Sage. You must type 3*x^2 (3x^2 will not work).
Also, don't forget the parentheses. They are often required around the numerator and denominator of fractions.
I will give the function a name first, and then I will graph it.
It is also possible to plot a function without giving it a name. However, since we usually do more than one thing with our functions, it is usually worth it to define the function first.
The default plot window uses , and Sage choose the range on the y-axis to fit the graph to the window.
If you want to specify a new window, use the xmin, xmax, ymin, and ymax options.
To graph more than one function, add plots together.
Example 2
Add a graph of to the graph of .
Note: the domain of is , so I have set xmin=0 for the plot of . If you have xmin less than 0, Sage will give you a warning.
To distinguish between the two functions, you can change the color and/or the line style.
For example, to change the color to red, add color='red' to the plot (notice the quotation marks around the color name). Sage knows many colors; feel free to experiment.
To change the line style to dashed, add linestyle='dashed' to the plot (again, notice the quotation marks). You can also use 'dotted' or 'dashdot' instead.
For more about graphing, refer to the Calculus 1 lab "Graphing and Solving Equations."
Limits
The "limit" command is used to find limits of functions. To take a limit as x approaches a, you add x=a to the limit command.
Example 3
Find
For one-sided limits, add dir='right' or dir='left' (notice quotation marks).
Find the following:
Example 4
Find
Any variable other than x has to be "declared." In this example, "%var t" tells Sage that t is a variable.
For more about limits, refer to the Calculus 1 lab "Limits."
Derivatives
You compute derivatives in Sage using the "derivative" command.
Example 5
Given , compute the following:
If you want to compute particular values of the derivative, then define a new function equal to the derivative. Sage does not allow f', so I like to call my derivative df, for "derivative of f." You can use any name you want (just don't call it f again).
Example 6
Given , compute the following:
For more about derivatives, refer to the Calculus 1 lab "Differentiation."
Integrals
To compute an integral in Sage, use the "integral" command. Here is an indefinite integral (antiderivative). This requires two arguments: the function to be integrated and the variable of integration.
Example 7
Given , compute
Here is a definite integral. This requires two additional arguments: the lower and upper limits of integration.
Example 8
Given , compute
Example 9
Compute
Don't forget to declare variables first.
For more about integrals, refer to the Calculus 1 lab "Symbolic Integration."