Your first notebook
You'll be using CoCalc to author notebooks: Documents that combine writing and calculations. Before you can start a notebook, you'll need to set up a project.
Your first project
A project is like a folder for your work. But you have to create one before you can do anything else.
After you Create an account on CoCalc, or after you sign in, you'll land on the Projects page.
- Fill in a project name. (Don't worry, you can change this later.)
- Click the "Create Project" button.
- Click on the name of your newly-created-project to open the project. You'll see an empty project. We'll start adding files....
Jupyter notebook
Unless otherwise noted, Calculus I students will be working with Jupyter notebooks. Start your first notebook:
- Fill in the name of the notebook. Here I'm calling it nb1
- Click on the Jupyter notebook button.
Your new notebook will open. Let's get oriented...
- The name of your Jupyter notebook file, here nb1.ipynb, shows up in the active file tab. ".ipynb" is the file extension for Jupyter notebooks.
- At the top right, the name of the running kernel, "SageMath (stable)" is shown. This is fine for most purposes. The kernel is the library that interprets your input code cells. You can switch to different kernels by selecting the "Kernel" menu item.
- The first input cell is highlighted in green.
- A drop-down menu shows that this input cell is a code cell, which we'll use for calculation. (You can drop down the menu and change the cell to be a "markdown" cell, which you'll use to write in.)
- Finally, there is a prominent green button that does the same as the File | Save menu item.
Calculate using SageMath
Let's use SageMath to convert 30 degrees to radians by multiplying by the conversion factor $\pi$ radians for every 180 degrees.
You'll type the calculation you wish to do into an input cell, and then hit Shift+Return to carry it out.
This results in an "output" cell with the result of your calculation:
- Unlike a calculator which gives you a decimal answer, SageMath will try to give you a symbolic answer. So, it has returned a simplified fraction of integers times the constant $\pi$.
- You have to use the * (asterisk) character to indicate multiplication. (Unlike Mathematica)
- Common constants are available in SageMath, such as pi, that is $\pi$, and e, the base of natural logarithms.
To get a numerical answer you could have used the "function" n(...) by enclosing the calculation inside the parentheses of the function. But we'll do something slightly different: The underscore character, '_' can be used to refer to the output of the most recent cell, so you can do this:
Many other useful functions:
- Trigonometry: sin(...), cos(...), arctan(...),
- Logarithms: log(...), exp(...) or e^(...),
- sqrt(...), abs(...),
Markdown cells: Documenting your work
What the notebook interface really shines at is mixing calculations with writing about those calculations (explanations).
The first step in writing about your work inside of a Jupyter notebook is to select a cell and change it from "code" to markdown
Now, you can type out what you'd like to write. Some of what you're typing will affect the appearance of what you write...
Pressing Shift+Return will cause the markdown to be "rendered":
In this example:
- Bold face text is produced by surrounding text with **...**. This is an example of markdown formatting.
Other things you can do with markdown formatting include: Different sized headings; paragraph breaks; italics; bulleted or numbered lists; hypertext links.
Find out more: Markdown cheatsheet (Github dialect).
- Enclosing text between dollar signs, \$ ... \$, causes it to be treated as LaTeX commands for producing properly typeset mathematics.
- A LaTeX command typically begins with a slash, such as \pi which renders as $\pi$.
- Some LaTeX commands look like functions, where the arguments are enclosed in curly brackets, {...}, such as
- \sqrt{x^2} which renders as $\sqrt{x^2}$.
- \frac{1}{a+b} which renders as $\frac{1}{a+b}$.
Find out more: MathJax basic tutorial - MathJax is a common package to let you use LaTeX commands in web documents.
The last thing to do in your Jupyter notebook is to re-arrange the cells a bit. To put our documentation cell before the calculation, use these buttons which allow you to move the selected cell up and down in the sequence.
The final result should look like this:
There are many other keyboard shortcuts to perform various operations on selected cells. Click on this button to see the keyboard shortcuts:
Finally, you can learn more about CoCalc and get help by clicking on these buttons:
And of course you can always search the web with terms like sagemath sin( ).
Cool! Go forth calculating and documenting!
>> NEXT: Miscellaneous SageMath tips if (! $homepage){ $stylesheet="/~paulmr/class/comments.css"; if (file_exists("/home/httpd/html/cment/comments.h")){ include "/home/httpd/html/cment/comments.h"; } } ?>