Difference between revisions of "Python/C2/Getting-started-with-sage-notebook/English-timed"
From Script | Spoken-Tutorial
Line 32: | Line 32: | ||
|- | |- | ||
|0:35 | |0:35 | ||
− | |Sage can do a lot of math stuff for you including, but not limited to, algebra, | + | |Sage can do a lot of math stuff for you including, but not limited to, algebra, calculus, geometry, cryptography, graph theory among other things. |
|- | |- |
Revision as of 15:03, 11 March 2013
Timing | Narration |
---|---|
0:00 | Hello friends and Welcome to this spoken tutorial on "Getting started with Sage and Sage notebook". |
0:07 | At the end of this tutorial, you will be able to,
|
0:30 | To start with, what is Sage? |
0:33 | Sage is a free, open-source mathematical software. |
0:35 | Sage can do a lot of math stuff for you including, but not limited to, algebra, calculus, geometry, cryptography, graph theory among other things. |
0:48 | It can also be used as an aid in teaching and research in any of the areas that Sage supports. |
0:53 | So let us start Sage now |
0:56 | We are assuming that you have Sage installed on your computer now. |
1:00 | If not please visit the sagemath dot org slash doc slash tutorial slash introduction dot html#installation for the tutorial on how to install Sage. |
1:13 | Now you can open the terminal |
1:17 | So, let us now learn how to start Sage. |
1:19 | So type on the terminal sage and hit enter |
1:27 | This should start a new Sage shell with the prompt sage. |
1:32 | So now we can type all the commands that Sage supports here. |
1:35 | But Sage comes bundled with a much more elegant tool called Sage Notebook. |
1:40 | So what is Sage Notebook? |
1:44 | Sage Notebook provides a web based user interface to use Sage. |
1:48 | So once we have a Sage notebook server up and running, all we want is a browser to access the Sage functionality. |
1:56 | For example there is an official instance of Sage Notebook server running at http colon double slash sagenb dot org. |
2:06 | You can visit that page, create an account there and start using Sage! |
2:09 | So all you need is just a modern browser to use Sage and nothing else! |
2:15 | The Sage notebook also provides a convenient way of sharing and publishing our work, which is very handy for research and teaching. |
2:23 | However we can also run our own instances of Sage notebook servers on all the computers, if we have a local installation of Sage to start the notebook server just type notebook and brackets. |
2:43 | This will start the Sage Notebook server. |
2:46 | If we are starting the notebook server for the first time, we are prompted to enter the password for the admin. |
2:52 | Type the password and make a note of it. |
2:54 | After this Sage automatically starts a browser page for you with the notebook opened. |
3:01 | If it doesn't automatically start a web page browser , check if the Notebook server started and there were no problems. |
3:10 | If so, open your browser and in the address bar, type the URL shown in the instructions upon running the notebook command on the sage prompt. |
3:20 | So you can type http colon double slash localhost colon 8000, in our case it is the point. |
3:31 | The notebook command gives an instruction telling Open your web browser to localhost colon 8000. |
3:40 | If you are not logged in yet, it shows the Notebook home page and textboxes to type the username and the password. |
3:48 | You can use the username 'admin' and the password you gave while starting the notebook server for the first time. |
3:54 | There are also links that recover forgotten password and to create new accounts. |
4:00 | Once we are logged in with the admin account we can see the notebook admin page. |
4:03 | A notebook can contain a collection of Sage Notebook worksheets. |
4:09 | Worksheet is basically a working area. |
4:12 | This is where we enter all the Sage commands on the notebook. |
4:17 | The admin page lists all the worksheets created. |
4:21 | On the topmost part of this page we have the links to various pages. |
4:27 | The home link takes us to the admin home page. |
4:30 | The published link takes us to the page which lists all the published worksheets. |
4:34 | The log link has the complete log of all the actions we did on the notebook. |
4:38 | We have the settings link where we can configure our notebook & the notebook server & create and manage accounts. |
4:45 | We have a link to help upon clicking opens a new window with the complete help of Sage. |
4:52 | The entire documentation of Sage is supplied with Sage for offline reference and this help link is the way to get into it. |
5:01 | Then we can report bugs about Sage by clicking on Report a Problem link and there is a link to sign out of the notebook. |
5:10 | We can create a new worksheet by clicking New Worksheet link |
5:13 | Sage prompts you for a name for the worksheet. |
5:16 | Let us name the worksheet as 'nbtutorial'. |
5:24 | Now we have our first worksheet which is empty. |
5:31 | Every Sage command must be entered in this cell. |
5:34 | A cell is equivalent to the prompt on console. |
5:37 | When we create a new worksheet, to start with we will have one empty cell. |
5:43 | Let us try out some math here |
5:46 | So you can type there 2 plus 2 |
5:52 | then 57 point 1 raised to 100 |
6:00 | The cap operator is used for exponentiation. |
6:04 | If you observed carefully, we typed two commands but the output of only last command was displayed. |
6:12 | By default each cell displays the result of only the last operation. |
6:16 | We have to use print statement to display all the results we want to be displayed. |
6:22 | Now we perform more operations, we want more cells. |
6:27 | So how do we create a new cell? |
6:30 | It is very simple. |
6:31 | As we hover our mouse above or below the existing cells we see a blue line, by clicking on this new line we can create a new cell. |
6:46 | We have a cell, we have typed some commands in it |
6:51 | So type matrix then within brackets 1,2,3,4 then charat then again in brackets minus 1. |
7:07 | but how do we evaluate that cell? |
7:09 | Pressing Shift along with Enter evaluates the cell. |
7:17 | Alternatively we can also click on the evaluate link and evaluate the cell given below. |
7:22 | After we create many cells, we may want to move between the cells. |
7:27 | To move between the cells use Up and Down arrow keys. |
7:31 | Also clicking on the cell will let you edit that particular cell. |
7:38 | To delete a cell, clear the contents of the cell and hit backspace |
7:41 | If you want to add annotations in the worksheet itself, on the blue line that appears on hovering the mouse around the cell, Hold Shift and click on the line. |
7:56 | This creates a What You See Is What You Get cell. |
8:09 | We can type in the editable cell. |
8:12 | This text contains both the bold text and italicized text. |
8:36 | Then you can type, it also contain bulleted list. |
9:02 | Then it also contain enumerated list. |
9:29 | In the same cell we can display typeset math using the LaTeX like syntax |
9:34 | So we have to type below that in dollar sign then slash int underscore zero raised to slash infty space e raised to power -x in curly braces then slash then dx then again a dollar symbol. |
9:54 | We enclose the math to be typeset within dollar and dollar or dollar dollar and dollar dollar as in LaTeX. |
10:02 | We can also obtain help for a particular Sage command or function within the worksheet itself by using a question mark following the command |
10:10 | So you can type for example sine question mark and hit enter. |
10:24 | You have to press shift enter. |
10:27 | Evaluating this cell gives me the entire help for the sine function inline and the worksheet itself. |
10:34 | Similarly we can also look at the source code of such command or function using double question mark |
10:39 | so for ex: you can type matrix question mark question mark then press shift and enter. |
10:48 | Sage notebook also provides the feature for autocompletion. |
10:52 | To autocomplete a command type first few unique characters and hit tab key. So you can type plot then tab |
11:07 | To list all the methods that are available for a certain variable or a datatype, we can use the variable name followed by the dot to access the methods available on it |
11:20 | So |
11:26 | you can type |
11:28 | s= |
11:33 | within single quotes hello |
11:37 | then s dot rep then tab |
11:51 | The output produced by each cell can be one of the three states. |
11:55 | It can be either the full output, or truncated output or hidden output. |
12:00 | The output area will display the error, if the Sage code was wrote in the cell did not successfully execute |
12:09 | So you can type a comma b is equal to 10 |
12:16 | The default output we obtained now is a truncated output. |
12:19 | Clicking at the left of the output area when the mouse pointer turns to hand gives us the full output |
12:30 | clicking again makes the output hidden and it cycles. |
12:38 | Lastly, Sage supports a variety of languages and each cell on the worksheet contain code written in a specific language. |
12:45 | It is possible to instruct Sage to interpret the code in the language we have written. |
12:54 | This can be done by putting percentage sign(%) followed by the name of the language. |
13:01 | For example, to interpret the cell as Python code we put as the first line in the cell percentage symbol then python. |
13:14 | Similarly we have: %sh for shell scripting,percentage fortran for Fortran, percentage gap for GAP and so on. |
13:25 | Let us see how this works. |
13:26 | Say I have an integer. |
13:28 | The type of the integer in default Sage mode is |
13:31 | a is equal to 1 |
13:34 | Then type within brackets a. |
13:45 | Output will be: type 'sage dot rings dot integer dot Integer'>> |
13:52 | or type within colon int |
13:58 | We see that Integers are Sage Integers. |
14:00 | Now let us put percentage python as the first line of the cell and execute the same code snippet |
14:09 | So you can type there in the cell |
14:13 | percentage python then a is equal to 1 then type a |
14:20 | So You can also get the Output colon type 'int'>< |
14:26 | Now we see that the integer is a Python integer. |
14:28 | Why? |
14:29 | Because now we instructed Sage to interpret that cell as Python code. |
14:36 | This brings us to the end of this tutorial. |
14:38 | In thus tutorial, we have learnt to, Know about Sage and sage notebook. |
14:42 | Start Sage shell and sage notebook. |
14:45 | Create accounts and start using the notebook. |
14:48 | Create new worksheets. |
14:49 | Access the menus available on the notebook. |
14:51 | Evaluate cells in the worksheet. |
14:54 | 7. delete the cells. and navigate around the cells. |
14:57 | 8. Make annotations in the worksheet. |
14:59 | 9. Use tab completions. |
15:00 | 10. Embed code of other scripting languages in the cells.
|
15:05 | Here are some self assessment questions for you to solve |
15:08 | 1. Each cell in a sage worksheet displays the result of only the last operation. |
15:13 | True or False. |
15:14 | 2. How do you evaluate a cell using the keyboard keys? |
15:17 | Shift key along with enter key |
15:19 | Control key along with enter key |
15:21 | Alt key along with enter key |
15:23 | And the answers, |
15:26 | 1.The answer is True. |
15:28 | By default each cell displays the result of only the last operation. |
15:31 | 2.We have to press Shift along with Enter evaluates the cell.
|
15:36 | So we hope you have enjoyed This tutorial and found it useful. |
15:41 | Thank you! |