This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is

licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

- Intro to 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.

You graph a function in Sage using the "plot" command.

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.

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."

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

2

For one-sided limits, add dir='right' or dir='left' (notice quotation marks).

Find the following:

2
2

Find

Any variable other than x has to be "declared." In this example, "%var t" tells Sage that t is a variable.

0

For more about limits, refer to the Calculus 1 lab "Limits."

You compute derivatives in Sage using the "derivative" command.

Given , compute the following:

24*x^5 - 24*x^2 + 2

120*x^4 - 48*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 , compute the following:

2

168

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 , compute

4/7*x^7 - 2*x^4 + x^2 - x

Here is a definite integral. This requires two additional arguments: the lower and upper limits of integration.

Given , compute

-6/7

Compute

Don't forget to declare variables first.

2/3*A^3*a + 2*A*c

For more about integrals, refer to the Calculus 1 lab "Symbolic Integration."