Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/141-Labs/Lab 01 - New Users Tour.ipynb
Views: 491
Lab 01 - New User's Tour
To take the tour, click in each executable cell, the ones with beside them, type the appropriate code, and execute the cell. You execute a cell by pressing . Note that simply pressing will go to the next line in the executable cell and will not execute the code.
SageMath is a free, open-source math software that supports research and teaching in algebra, geometry, number theory, cryptography, numerical computation, and related areas. SageMath is based on the programming language Python. We will use SageMath to perform calculations and give insight into the many topics covered in Calculus.
SageMath as a Calculator
SageMath's most basic function is to act as a conventional calculator. For example, we can use SageMath to simplify the expression We can simply input the expression into an executable cell exactly as we would a calculator. One thing to be careful about in SageMath is you must use to represent multiplication.
By default, SageMath does not display the output in a "nice" way. You can make SageMath display the output in a more convenient manner by using the () command.
Since the expression only contains rational numbers, SageMath gives the output as a rational number. If we wanted a decimal approximation of the output, we could use the command, where is the number of decimal places we want displayed.
A second way in which we could get a decimal approximation for a rational expression is to make at least one of the numbers a floating-point number. This means, make one of the numbers a decimal.
Predefined Functions and Constants
SageMath has many of the common math functions and constants predefined. Most of these can be referenced by their normal notation. Note how SageMath has no issue calculating , , and .
SageMath gave exact answers for and In the two cells below, use the ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: \textbf{show(\dotsParseError: KaTeX parse error: Expected 'EOF', got '}' at position 2: )}̲ command to better display the output of these two calculations.
If you wish to add more cells to the notebook, simply click the button in the toolbar above. You can also click on in the toolbar above and choose either or . This will insert a cell either above or below the current selected cell. By default, this will add an executable cell. Go ahead and add two new executable cells and use these cells to approximate the values of and to 5 decimal places.
You can also add a Markdown cell to the notebook. To do this, simply add a new cell and change the type from Code to Markdown. A Markdown cell is a cell which allows text. In addition to text, you can type in HTML and LaTeX code and the cell will compile this code into text. If you do not know HTML or LaTeX, then you can use the Markdown cells plainly as a cell for basic text. Use the button to add a Markdown cell at the very beginning of the document. In the cell, type your name, your section number, and any other information your TA would like you to include in your lab submission.
Assigning Expressions to Names
SageMath allows us to assign an expression to a name so that it can easily be referenced throughout the entire worksheet. For example, we can assign to the name by doing the following.
Note that SageMath supresses the output whenever you are making an assignment. We can check that really has been assigned to by entering into an input cell by itself.
Now, whenever we use throughout the entire worksheet, it will be referring to . If we wanted to reassign to something else, all we have to do is set it equal to the new value.
Note that this time, SageMath did display the new value of . This is because we both assigned to its new value and told SageMath to return in the same input cell. SageMath allows multiple lines of code in the same cell and will execute all lines, however, it will only display the last line of code.
If you wish to display mutliple lines, you can use the command.
Be very careful about the names you choose for your assignment variables. SageMath will allow you to use a name that it has already defined and it does warn you that you are overwriting a predefined command. For example, if you do the assignment sin = 5, then the next time you use sin, it will think you mean 5 instead of the trig function. In order to recover the trig function sin, you need to reset SageMath by using the command This will clear all variables and functions you previously assigned, so you will need to re-execute those codes to reassign the variables and functions.
Creating Functions
We can also create functions in SageMath. For example, in order to create the function , we do the following.
Simlilar to assignments, SageMath will not display any output when creating a function. It is good practice to call the function after creating it in order to verify that you created the intended function.
Now that we have defined, we can evaluate the function at different inputs.
What if we wanted to use the variable in place of ?
SageMath gives an error saying that is not defined. The only variable that SageMath has predefined is . If we want to use other variables, such as , then we will need to make a variable by using the command.
Now, SageMath will have no problem evaluating .
Rather than just doing normal calculations, we can also have SageMath perform calculus.
Plotting
The last part of SageMath which we will explore in this tour is its ability to plot graphs of functions. First, use the cell below to create the function
Now, plot by using the function .
The function can take inputs other than just . The other inputs allow you to change specific characteristics about the graph of the funciton such as the -range and -range, the color, the linestyle, etc. To see a detailed description about the plot function, or about any function, simply follow its name with and execute the cell.
We can run the following code to display the graph of in a window that goes from on the -axis and on the -axis, changes the graph color to red, and changes the linestyle to dashed.
SageMath also has the ability to graph multiple functions at once. When plotting multiple functions at the same time, surround them in brackets. Also, you can change properties for each function by also surrounding the properties in brackets. The following command plots both and its derivative from on the -axis and on the -axis. It also plots in green with dashes and in orange with dots. Additonally, we add a legend to distinguish between the two functions in the graph.
Converting Notebook to PDF for Submission
Once you are done with a lab, you will submit a PDF version of the notebook to Blackboard for your TA to grade. The easiest way to convert the Notebook file to a PDF file is to choose ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: \textbf{File \rightarrowParseError: KaTeX parse error: Expected 'EOF', got '}' at position 15: Print Preview}̲ from the toolbar at the top of the page. Then, press ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: \textbf{CTRL +ParseError: KaTeX parse error: Expected 'EOF', got '}' at position 3: P}̲ and choose to . You can upload the PDF to Blackboard.
Note: These instructions may differ depending on Web Browser and Operating System.