Sage is an open-source (and free) mathematical software system. SageMathCloud is a way to use Sage through a web browser, without having to install Sage on your own computer. We will use Sage in this course to explore some Calculus using software tools.

Let's start with an easy calculation. Below you will see a *Sage cell*, with `2+2`

already entered. Click inside the cell, then hit `Shift-Return`

to evaluate the cell and get the result:

8

(You can also click on a gray line to get a *new* Sage cell in which to enter your own calculation. Try it out!)

As the above example shows, Sage can be used as a calculator. But Sage is a very *good* calculator, which knows about all sorts of mathematical functions and constants. To see an example, let's start a new cell by clicking on a gray line below. Then type `sin(pi/3)`

and press [Shift]-[Enter] to see a little of what Sage can do.

1/2*sqrt(3)

That's really good! But if you want to see a numerical approximation to the number $\sin(\pi/3)$, you can use the Sage function `n`

. You can also use the symbol `_`

to refer to the *last* computation that Sage did. So if the last thing you computed was `sin(pi/3)`

above, you can type `n(_)`

to find a numerical approximation. (If you have entered something else since then, just type `n(sin(pi/3))`

in a new cell.)

0.866025403784439

If you want more accuracy, you can add the argument `digits`

inside the `n`

function, like this:

1.4142135623730950488016887242096980785696718753769

Sage is familiar with many functions you know about. A few notes about some special ones:

- The inverse trig functions are written as
`arcsin`

,`arctan`

, etc. - The natural logarithm can be written as
`ln`

or as`log`

. If you want a logarithm to another base, such as base 10, specify the base with the`base`

argument:`log(x, base=10)`

, for example. - The natural exponential function, $e^x$, can be written as
`exp(x)`

.

6

**Practice** Can you find (to at least six decimal places) the angle which makes $\sin(x)$ equal to 1/3?

Sage can do symbolic algebra, but you must first declare any variables you want to use. Let's declare both `x`

and `t`

to be symbolic variables with the statement below:

(x, t)

Here are a few examples of what Sage can do with algebraic expressions: (Note in the examples below, multiplication **must** be indicated with a `*`

; it cannot be represented by juxtaposition!)

2*x^2 + 9*x - 5

$\displaystyle 2 \, x^{2} + 9 \, x - 5$

2*(3*x - 2)*(x + 5)*x

3 * 7 * 826849

[x == -3, x == 2]

-15/(x - 2) + 23/(x - 3) + 1

$\displaystyle -\frac{15}{x - 2} + \frac{23}{x - 3} + 1$

It is also easy to define a simple function, so that you can reuse it many times, if you wish. Here's an example of creating a function $f(x) = x^2 + 2$:

When you run the cell above, nothing seems to happen, because all it does is define the function. But now you can use the function $f$, if you wish:

6

There are *many* other types of algebraic problems that Sage can solve. See some of the references at the end if you would like to learn more.

Sage can also carry out some basic symbolic calculus. Here are a few examples:

x
6*x*e^(x^2) + 1/x

2*t^2*x

1/4*x^4 + 1/2*x^2 + x

1/2

-1/720*x^6 + 1/24*x^4 - 1/2*x^2 + 1

$\displaystyle -\frac{1}{720} \, x^{6} + \frac{1}{24} \, x^{4} - \frac{1}{2} \, x^{2} + 1$

It is easy to plot a function in Sage. Here is an example of plotting the function $f(x) = 3 x^2 + 2 x - 1$ on the interval $[-2, 2]$:

Sometimes the graph does not show the sorts of details you would like. Try the following to plot $\tan(x)$ on $[-\pi, \pi]$:

The $y$ values get so big that we cannot see much else. We can add the extra arguments `ymin`

and `ymax`

to the plot function to fix the window of the plot:

By the way, those vertical lines probably look like Sage is plotting the asymptotes. Actually, it's just the result of Sage "connecting the dots" as it plots the graph. We can adjust the behavior at these points using the `detect_poles`

option:

We are more interested in plots of functions of several variables. Here's how to plot a surface:

(x, y)

3D rendering not yet implemented

A useful trick is to plot an *implicit surface*, where a function is equal to a given value. Here we can plot a sphere, by plotting where $x^2 + y^2 + z^2 = 1$:

(x, y, z)

3D rendering not yet implemented

Sage is also capable of plotting parametric plots in space, using `parametric_plot3d`

:

t

3D rendering not yet implemented

To combine two plots, just add them:

3D rendering not yet implemented

Sage is familiar with vectors and vector operations. You can define a vector as a list of numbers using the `vector`

function:

$\displaystyle \left(1,\,2,\,3\right)$

Sage understands common operations, and even knows about dot and cross products:

(7, 0, 5)
(5, 8, -7)
4
4

Matrices are created using the matrix command, but you need to tell sage what kinds of entries the matrix should have. We will use rational numbers, indicated by `QQ`

. Then we enter the matrix as a list of lists. We define a matrix `m`

$\displaystyle \left(\begin{array}{rrr}
3 & 2 & 0 \\
1 & -1 & 1 \\
-1 & 1 & -5
\end{array}\right)$

[1 0 0]
[0 1 0]
[0 0 1]

[-5.305282147755060?, -1.105324652427052?, 3.410606800182113?]

Sage is a full featured programming language. Here is a simple example of a function defined to test if a function is even or not:

False

If you are familiar with Python, Sage uses the same syntax.

This is text. We can include *italic*, or **bold**.

Finally, to write your responses to some Sage problems, you will want to be able to put in some text explanations. The easiest way to do this is using *markdown*, a simple language for formatted text. To start a markdown cell, put `%md`

as the first text in the cell. Then you can type any text you want, and when you evaluate that cell, it will mostly just turn in to text. Here are a few simple formatting commands you can add, if you wish

- To type
*italicized*text, surround the words with an asterisk:`*italicized*`

- To make text
**bold**, use two asterisks:`**bold**`

- Trickier: You can format a polynomial like $f(x) = 3 x^3 - x^2 + 2x + 1$ like this:
`$f(x) = 3 x^3 - x^2 + 2x + 1$`

(That last example is very tricky. There is an entire language for mathematical typesetting called $\LaTeX$ which is being used there. You are not required to use this notation, but you are welcome to try if you wish.)

All of the text you see in this document is really in a markdown cell. If you double click on one of those cells, you can see exactly how I created that text, if you are interested.

(Alternatively, you can also start a cell with `%html`

, and Sage will recognize and render HTML as well.)

Here are some useful references if you would like to explore Sage further:

- The Official Sage Tutorial
- A lengthy (but very good) Sage Tutorial at San Diego State University.
- Gregory Bard at University of Wisconsin, Stout, has a page of information about Sage, including some videos and his new book,
*Sage for Undergraduates*.

x f(x)
+--------------------+-------------------+
-0.590000000000000 -28.4380000000017
-0.599000000000000 -287.639800000051
-0.599900000000000 -2879.63998000200
-0.610000000000000 29.1579999999997
-0.601000000000000 288.359800000013
-0.600100000000000 2880.35998001141
-0.600010000000000 28800.3599988519

10/13

[(1, 1/2), (2, 10/13), (3, 1)]

Sage is an open-source (and free) mathematical software system. SageMathCloud is a way to use Sage through a web browser, without having to install Sage on your own computer. We will use Sage in this course to explore some Calculus using software tools.

Let's start with an easy calculation. Below you will see a *Sage cell*, with `2+2`

already entered. Click inside the cell, then hit `Shift-Return`

to evaluate the cell and get the result:

8

(You can also click on a gray line to get a *new* Sage cell in which to enter your own calculation. Try it out!)

As the above example shows, Sage can be used as a calculator. But Sage is a very *good* calculator, which knows about all sorts of mathematical functions and constants. To see an example, let's start a new cell by clicking on a gray line below. Then type `sin(pi/3)`

and press [Shift]-[Enter] to see a little of what Sage can do.

1/2*sqrt(3)

That's really good! But if you want to see a numerical approximation to the number $\sin(\pi/3)$, you can use the Sage function `n`

. You can also use the symbol `_`

to refer to the *last* computation that Sage did. So if the last thing you computed was `sin(pi/3)`

above, you can type `n(_)`

to find a numerical approximation. (If you have entered something else since then, just type `n(sin(pi/3))`

in a new cell.)

0.866025403784439

If you want more accuracy, you can add the argument `digits`

inside the `n`

function, like this:

1.4142135623730950488016887242096980785696718753769

Sage is familiar with many functions you know about. A few notes about some special ones:

- The inverse trig functions are written as
`arcsin`

,`arctan`

, etc. - The natural logarithm can be written as
`ln`

or as`log`

. If you want a logarithm to another base, such as base 10, specify the base with the`base`

argument:`log(x, base=10)`

, for example. - The natural exponential function, $e^x$, can be written as
`exp(x)`

.

6

**Practice** Can you find (to at least six decimal places) the angle which makes $\sin(x)$ equal to 1/3?

Sage can do symbolic algebra, but you must first declare any variables you want to use. Let's declare both `x`

and `t`

to be symbolic variables with the statement below:

(x, t)

Here are a few examples of what Sage can do with algebraic expressions: (Note in the examples below, multiplication **must** be indicated with a `*`

; it cannot be represented by juxtaposition!)

2*x^2 + 9*x - 5

$\displaystyle 2 \, x^{2} + 9 \, x - 5$

2*(3*x - 2)*(x + 5)*x

3 * 7 * 826849

[x == -3, x == 2]

-15/(x - 2) + 23/(x - 3) + 1

$\displaystyle -\frac{15}{x - 2} + \frac{23}{x - 3} + 1$

It is also easy to define a simple function, so that you can reuse it many times, if you wish. Here's an example of creating a function $f(x) = x^2 + 2$:

When you run the cell above, nothing seems to happen, because all it does is define the function. But now you can use the function $f$, if you wish:

6

There are *many* other types of algebraic problems that Sage can solve. See some of the references at the end if you would like to learn more.

Sage can also carry out some basic symbolic calculus. Here are a few examples:

x
6*x*e^(x^2) + 1/x

2*t^2*x

1/4*x^4 + 1/2*x^2 + x

1/2

-1/720*x^6 + 1/24*x^4 - 1/2*x^2 + 1

$\displaystyle -\frac{1}{720} \, x^{6} + \frac{1}{24} \, x^{4} - \frac{1}{2} \, x^{2} + 1$

It is easy to plot a function in Sage. Here is an example of plotting the function $f(x) = 3 x^2 + 2 x - 1$ on the interval $[-2, 2]$:

Sometimes the graph does not show the sorts of details you would like. Try the following to plot $\tan(x)$ on $[-\pi, \pi]$:

The $y$ values get so big that we cannot see much else. We can add the extra arguments `ymin`

and `ymax`

to the plot function to fix the window of the plot:

By the way, those vertical lines probably look like Sage is plotting the asymptotes. Actually, it's just the result of Sage "connecting the dots" as it plots the graph. We can adjust the behavior at these points using the `detect_poles`

option:

We are more interested in plots of functions of several variables. Here's how to plot a surface:

(x, y)

3D rendering not yet implemented

A useful trick is to plot an *implicit surface*, where a function is equal to a given value. Here we can plot a sphere, by plotting where $x^2 + y^2 + z^2 = 1$:

(x, y, z)

3D rendering not yet implemented

Sage is also capable of plotting parametric plots in space, using `parametric_plot3d`

:

t

3D rendering not yet implemented

To combine two plots, just add them:

3D rendering not yet implemented

Sage is familiar with vectors and vector operations. You can define a vector as a list of numbers using the `vector`

function:

$\displaystyle \left(1,\,2,\,3\right)$

Sage understands common operations, and even knows about dot and cross products:

(7, 0, 5)
(5, 8, -7)
4
4

Matrices are created using the matrix command, but you need to tell sage what kinds of entries the matrix should have. We will use rational numbers, indicated by `QQ`

. Then we enter the matrix as a list of lists. We define a matrix `m`

$\displaystyle \left(\begin{array}{rrr}
3 & 2 & 0 \\
1 & -1 & 1 \\
-1 & 1 & -5
\end{array}\right)$

[1 0 0]
[0 1 0]
[0 0 1]

[-5.305282147755060?, -1.105324652427052?, 3.410606800182113?]

Sage is a full featured programming language. Here is a simple example of a function defined to test if a function is even or not:

False

If you are familiar with Python, Sage uses the same syntax.

This is text. We can include *italic*, or **bold**.

Finally, to write your responses to some Sage problems, you will want to be able to put in some text explanations. The easiest way to do this is using *markdown*, a simple language for formatted text. To start a markdown cell, put `%md`

as the first text in the cell. Then you can type any text you want, and when you evaluate that cell, it will mostly just turn in to text. Here are a few simple formatting commands you can add, if you wish

- To type
*italicized*text, surround the words with an asterisk:`*italicized*`

- To make text
**bold**, use two asterisks:`**bold**`

- Trickier: You can format a polynomial like $f(x) = 3 x^3 - x^2 + 2x + 1$ like this:
`$f(x) = 3 x^3 - x^2 + 2x + 1$`

(That last example is very tricky. There is an entire language for mathematical typesetting called $\LaTeX$ which is being used there. You are not required to use this notation, but you are welcome to try if you wish.)

All of the text you see in this document is really in a markdown cell. If you double click on one of those cells, you can see exactly how I created that text, if you are interested.

(Alternatively, you can also start a cell with `%html`

, and Sage will recognize and render HTML as well.)

Here are some useful references if you would like to explore Sage further:

- The Official Sage Tutorial
- A lengthy (but very good) Sage Tutorial at San Diego State University.
- Gregory Bard at University of Wisconsin, Stout, has a page of information about Sage, including some videos and his new book,
*Sage for Undergraduates*.

x f(x)
+--------------------+-------------------+
-0.590000000000000 -28.4380000000017
-0.599000000000000 -287.639800000051
-0.599900000000000 -2879.63998000200
-0.610000000000000 29.1579999999997
-0.601000000000000 288.359800000013
-0.600100000000000 2880.35998001141
-0.600010000000000 28800.3599988519

10/13

[(1, 1/2), (2, 10/13), (3, 1)]