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.
You graph a function in Sage using the "plot" command.
Graph $\displaystyle f(x)=\frac{\sqrt{x^2+9}}{3x^2+2}$.
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 $-1 \le x \le 1$, 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.
Add a graph of $g(x)=\sin(\ln(x))$ to the graph of $f$.
Note: the domain of $g$ is $x > 0$, so I have set xmin=0 for the plot of $g$. 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."
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.
Find $\displaystyle\lim_{x\to 1}\frac{x^2-1}{x-1}$
For one-sided limits, add dir='right' or dir='left' (notice quotation marks).
Find the following:
$\displaystyle\lim_{x\to 1^+}\frac{x^2-1}{x-1}$
$\displaystyle\lim_{x\to 1^-}\frac{x^2-1}{x-1}$
Find $\displaystyle\lim_{t\to-4}\frac{t+4}{\sqrt{t+4}}$
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."
You compute derivatives in Sage using the "derivative" command.
Given $f(x)=4x^6-8x^3+2x-1$, compute the following:
$f'(x)$
$f''(x)$
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).
Given $f(x)=4x^6-8x^3+2x-1$, compute the following:
$f'(1)$
$f''(-1)$
For more about derivatives, refer to the Calculus 1 lab "Differentiation."
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.
Given $f(x)=4x^6-8x^3+2x-1$, compute $\displaystyle\int f(x)\, dx$
Here is a definite integral. This requires two additional arguments: the lower and upper limits of integration.
Given $f(x)=4x^6-8x^3+2x-1$, compute $\displaystyle\int_{-1}^{1} f(x)\, dx$
Compute $\displaystyle\int_{-A}^{A} at^2+bt+c\, dt$
Don't forget to declare variables first.
For more about integrals, refer to the Calculus 1 lab "Symbolic Integration."