Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004

Just Enough Sage

Creative Commons Attribution-NonCommercial-ShareAlike 3.0

Mike May, S.J., 2010

The purpose of this worksheet is to learn just enough of sage to be able to use it for this course.

The first detail is to make sure you are running an active copy of the worksheet. 

Look at the upper left corner of your browser window. 

If you see the option to "edit a copy", you do not yet have a live copy.  Select "edit a copy".

When running a sage worksheet you will want to:

  • Evaluate cells with mathematics (this includes plots),
  • Add new cells for mathematics
  • Add text regions to comment and document
  • Edit text

We now walk through the process for each of these 4 actions.

The easiest operation is evaluating a cell that someone has already prepared for you.  Notice the two math cells pictured below, which also appear beneath the text region.

When the cursor in in the math region, it becomes active.  An evaluate link appears.  You can evaluate the region either by shift-entering with the cursor in the region, or by clicking the evaluate link.  When you do either, the cursor evaluates the contents of the cell, prints out the last result, and moves the cursor to the next math cell.

As you can see, we can use sage to do easy calculations, or longer computations we would not want to do by hand.

2*3+7
13
2^123
10633823966279326983230456482242756608

A simple return stats a new line in the current cell without evaluating the cell.

If you evaluate a cell with two lines, the default is to only print out the last result.

You can get around this in a number of ways:

  • put the two values on one line, separated by a semicolon
  • assign the values to names, and then print the names
  • print the values asa  list done in one line.
2+3 5+6
11
2+3; 5+6;
11
2+3; 5+6;
5 11
a=2+3 b=5+6 print(a, b)
(5, 11)
print(2+3, 5+6)
(5, 11)

The next skill to learn is to be able to add a math cell in between existing cells.

As you can see in the picture, when you have the cursor just above a math cell, a thin blue line appears.  Clicking while your cursor in in the blue line will cause another math cell to appear above the current cell.

You should use this technique to insert a new cell above the cell that evaluates "2+3; 5+6;".

In that cell, evaluate "1+2+3+4".

The next skill to learn is to be able to add anotations to a worksheet.

Asa  general rule, in this class, raw computer output will never be considered a correct aswer.  At the very least, you need to identify which portion of the output is the answer, and what question it is answering.  (Think of this as the equivalent of puting boxes around your answer.)

Suppose that we are given the trivial asignment of adding 1 and 2 and also of adding 1, 2, and 3,  The answers are obviously 3 and 6.  We do the annotation by moving the cursor just above a math cell as before.  This time, we shift-click on the blue line.  That produces a new text region where we can type in text.

You should now add a math cell below where you add the integers 1, 2, 3, 4, and 5, and then add an annotation explaining the result.

1+2
3

The sum of 1 and 2 is 3.

1+2+3
6

The sum of 1 and 2 and 3 is 6.

1+2+3+4+5
15

The sum is 15

If you want to edit the text in a live worksheet, you simply double click on a piece of text.  That will bring up the editing window.

Renaming, Saving, Sharing, and Publishing

The last set of skills we will look at cover how you should save and turn in your work in such a way as to get credit for it.

The first task is to rename your copy of the worksheet so that I can tell whose it is.  A good method is to simply add your name to the name of the worksheet.  Thus I would change the worksheet title from "Just Enough Sage" to "Just Enough Sage - May".

In the upper left corner of the worksheet, select the combo box for file, and from the drop down menu, select rename worksheet.

This will bring up a dialog box which you can use to rename the worksheet.

In the upper right corner of the worksheet is a series of buttons.

The save worksheet should be used often.  You want to save as often as needed so that you will not be upset when you lose all the work since your last save.

The publish button is used to let the whole world see your work.  You should not do this with your homework.

The share button will be how you turn your work in.  You will want to share with user maymk.

The picture below shows how I share a file with user mikemay.

You should rename your copy of the worksheet with your name in the new name.  You should then share it with me.