2. A Mathematica  Session

2017-03-14

$Version

Remark: A part of the commands described below are specific to the Linux system of the computers used in the 
Physics Institute “Computerraum” or those of the Institute of Theoretical Physics - Computational Physics.

2.1  Notebook Interfaces

Mathematica  supports a special "notebook" interface on computers with graphical user interfaces.

2.1.1  Starting Mathematica

To start Mathematica  on a PC in the computer lab, one  may
either (using the left mouse button)

							         
          click gear wheel in lower left corner of screen - click Terminal - in terminal window: :- $ mathematica & - 	
          - Return

A notebook file contains all the input statements and the corresponding outputs (formulae and graphics). This file can be reworked and edited during the session. It is a postscript file; so it is rather lengthy, in particular if it contains graphics or the interpolating functions resulting from NDSolve[] (cf.11.2). So it is commendable to delete the graphics or data output before storing such a file on a small soft disk. Most USB sticks are large enough for storing such notebooks.

2.1.2	 The Kernel

As soon as the notebook starts to work a second domain is opened in the central processing unit, the kernel. This contains all the rules Mathematica knows and uses. There the real processing is done. It is even possible to have the kernel on an other, maybe more powerful, computer than the notebook.

2.1.3	An example of a notebook

$Version

Clear[x,y]

x = π

y = 5

x + y

N[%]

Clear[x]

NIntegrate[Exp[- x 0.00001] Sin[100 x],{x,0,Infinity}]

Warning:  In Apple (MaxIntosh computers)  in an own window "Messages":

int =Chop[ Integrate[Exp[- x 0.00001] Sin[100 x],x]]

iog = int /. x ->  Infinity//N

iug = (int /. x ->  0)//N

iog - iug

2.2  A Mathematica  Session on a PC

Abbreviations used below:   
pcucc		Point the cursor to the text or icon indicated and press the left button
		of the mouse twice.
pcuc		Same as above, but press the button only once.
plb		Press left button of the mouse.
Ctrl		= Strg  on German type key bords

2.2.1  Starting a Session.

It is assumed that a Mathematica notebook window is open (see 2.1). Type the statements for your first operation. The statement line is terminated and sent to the kernel by pressing either the keys "shift" and "↵" (= carriage return)  simultaneously or by pressing the button "Enter" in the lower right corner of the key bord. This starts the  loading of the kernel, which takes a certain time.  Then Mathematica gives the result. Thereafter type the next statement and terminate it as just described.

2.2.2 	Opening a File

pcuc  to "File" in the upper left corner, in the appearing menue pcuc "Open". A new window with the name "Open" appears. There you see a directory and notebooks in it. Then you chosse the wanted file or you select asnother directory. 
Short command: "Ctrl o"

2.2.3 	Closing a File

pcuc  to "File" in the upper left corner, in the appearing menue pcuc "Close". 
Short command "Ctrl w"
 If the file has not been saved before, you will be asked wether you want to do so and to assign a name to it. In general, the file is stored in a directory with the following name: "Directory/Filename".

2.2.4 	Saving a File

If you are reworking a file saved before just fpcuc  to "File"  In the appearing menue pcuc "Save". 
Short command "Ctrl s"
 If the file has not been saved before, you will be asked whether you want to do so and to assign a name to it. In general, the file is stored as: "Directory/Filename".
 You may save a notebook under a new name by  pcuc  to "File"  In the appearing menue pcuc "Save as". 
Short command "Ctrl S"

2.2.5 	Importing  a File from an USB Stick

Insert an USB stick into the appropriate slot of the computer.  Use the Dateimanager (s. 2.1.1).
The name of the stick appears at the end of the left column of the menue. If you pccuc that name the Dateimanager will open a window showing you the content of the stick. 
If you pccuc at the name of a notebook then that Mathematica notebook will open.
Or you may use the cursor to draw a notebook file or that of a directory to the list the Dateimanager opened
before.

2.2.6 	Transfering a File or Directory to a USB Stick

Insert a USB stick into the appropriate slot of the computer. Apply the Dateimanager as described just before.  Draw the name or symbol of the notebook or the directory contained in your personal list on tne computer to 
the list of the stick.

2.2.7 	Closing a Session

pcuc  to "File" in the upper left corner, in the appearing menue pcuc "Quit".

2.2.8  	Short Commands for Typing

There are menues for short commands. Point the pointer to "Palettes" and plb. In the appearing menue you may choose: Basic Math Assistant, Class Room Assistant or Writing Assistant. For example, in Writing Assistant  or Basis Math Assistant open "Typesetting".   There you may chose  one menue by clicking at one of the rectangles in the next line.  In the table point the pointer to the wanted symbol and click once; then the symbol appears at the position of the pointer in the notebook just under construction. - Or clicking at the  the question mark besides "Typesetting"  you open a menue offering you:  Special Characters, Greek Letters, Operators, ... . When you choose the line "Greek Letters" in the menue you get a page displaying the symbols and various (short) commands for this symbol, for example: 

α  →  Esc a Esc	β →  Esc b Esc		ϕ → Esc f Esc		ω → Esc w Esc  .

In  Basic Math Assistant you find symbols for mathematical operations as e.g.  lists, sums,  Integration, derivation.  A black square indicates that the symbol upon which the operation shall be applied must be marked.

Short commands spare one the trouble to open the corresponding menues. This applies also for
file operations, s. 2.4.
The short commands for file operations are shown in the menu "File".  For example:
("Ctrl " denotes "Strg".)  E.g.: 
 Cut → Strg + x,    Copy → Strg + c,  Paste  →  Strg + v;  Save As →  Shift +Strg + s.

2.2.9  Interrupting a Calculation

A task may be aborted or  interrupted by  pcuc "Evaluation", pcuc "Abort" or "Interrupt". If this does not help try: pcuc "File", pcuc "Quit".  The content of the file which has not been saved before is lost.
So frequent saving may spare you annoyances of retyping.

2.2.10  Marking Characters or Expressions

Characters, words, commands, expressions are marked by drawing the cursor over them by shifting the mouse with the left button pressed; or by pressing  "Shift" and using the arrow buttons to shift the cursor.

2.2.11	Inserting Text

Comments and other text my be inserted in either of two ways:
1)	(*  .....  *)  may be inserted in input cells. Mathematica will ignore this.
2)	In a text cell. Menue Format -> submenue  Style ->  Text.  Then type the text.   
	Short command: Alt 7  or  
	Mark an existing cell (e.g. input commands) and type the commands given in the preceeding lines.

2.2.12  Inserting Titles or Headings

Menue Format -> submenue  Style ->  Title, Subtitle, ...,  Section, Subsection, ...., Text.  Then type the text.   
Short command : Alt 1, Alt 2, Alt 3, Alt 4, Alt 5, Alt 6, Alt 7;    or
Mark an existing cell (e.g. input commands) and type the commands given in the preceeding lines.

2.2.13	Transforma a  String Cell  into an Expression Cell

Mark the cell. Menue Format -> submenue  Style ->  Input;  or short command: Alt 9.

2.2.14	Help

In the menue Help one finds the online version of  Wolfram's Mathematica  book :
Virtual book ;
and  information on the working of a Mathematica command:
 Find Selected Function
 e.g. for  Integrate .
 At the end related commands are listed.

2.3  Cells, Groups, Text, Editing

Notebook files have the extension *.nb .  Statements and commands (including graphics) are displayed on the screen in cells.    Each cell is connected by the outermost square bracket at the right.  It contains input statements   (e.g. In[3] )  in the first group having a square bracket with a triangle at the upper corner;   output (e.g. Out[3] ) (resulting expressions, graphics, warnings, error messages) in the subsequent groups having a horizontal bar just below the triangle at the upper end of the square bracket. 

Text (which will not be executed) is marked by a square bracket with an additional horizontal bar at the upper corner. A cell may be transformed into a text cell by marking it and then using the menus:
Format, Style, Text; or the short command Alt + 7.
A text cell is transformed into a Mathematica input line by marking it and the using the menus:
Format, Style, Input; or the short command Alt + 9.

2.3.1 	Deleting, Copying or Pasting a Cell or Group

Mark the appropriate square bracket;  pcuc "Edit", pcuc "Cut".  The content of the cell or group so removed is stored in a paste basket; the previous content of that basket is destroyed. The new content may be pasted to another place of the file, or even in another file, by "Paste". If you pcuc "Copy", then the content of a cell or group is copied  into the paste basket;  the content of the place of origin remains unchanged. Instead of using the Edit menue, on may just use a short command,  which is indicated in the corresponding line of the menue, cf. the examples given just before 2.2.6 .

2.3.2 	Deleting, Copying  or Pasting Text

The same editing commands may be used to delete,  move  or copy text, e.g. lines, words, statements or parts of input text.  Point the cursor to the text to be treated, mark it by brushing the cursor over it holding down the left button of the mouse.

2.3.3  Splitting a Cell in Two.

pcuc at the position where the split should be done. pcuc "Cell", pcuc "Divide Cell".

2.3.4  Merging Two or Several Groups or Cells

Mark the brackets belonging to the groups or cells to be merged.;then pcuc "Cell", pcuc "Merge Cells". Unwanted results may occur as cells or groups of different type as e.g. input and output groups are merged. Merging an input and output group transforms the output into input.

2.4 File Operations

Files are opened from the harddisk into a notebook with the help of menues of the notebook, the same applies for saving notebooks. Files are transported from the harddisk to a floppy by commands issued in aTerminal window. This applies also to transfering files from one computer to an other one.

2.4.1	Opening Files from a Notebook

pcuc "File", pcuc "Open". In the appearing window pcuc choose the directory and the file. pcuc OK.

2.4.2	Saving a Notebook

If the notebook was already stored or has been saved before, pcuc "File", pcuc "Save".
Short command: 	Strg + s.
If a new notebook is to be saved or an old one under a new name, use "Save As" in "File",
select in the appearing window the wanted directory, type the (new) name and OK.
Short command: 	Strg +Shift + s.

2.4.3  Printing a Notebook

pcuc "File", pcuc "Print".  Short command: 	Strg + p.
Mark the appropriate box(es)  in the appearing window for printing or/and storing a  file.

2.4.4  Printing Parts of a Notebook

Mark the cells or groups to be printed. pcuc "File", pcuc "PrintSelection...". Proceed as in 2.4.3.
The short command is:   Strg + Shift +  p.

2.4.5  Deleting Files

In the terminal window you may delete files contained in a directory of your harddisk by the following unix commands (rm = remove ):
	rm filename.ext ;
or  all file(s) of a certain type characterised by the extension “.ext” by:
	rm *.ext .

2.4.6   Copy a File to and from another Computer.

Open a Terminal window, if there is none ready. Type the command "sftp" and the host name of the computer, on request the userid, thereafter on a new request the password. ls  is the command for getting a listing of the files or directories; cd for changing directories. 
You get a file by:
  	  get filename.ext.  
 Your may ask for all files with a given extention by:
	mget  *.ext.  
The corresponding commands for transfering files to an other computer just
write "put" in place of "get".

2.5   Schnizer’s WebSite:

http://www.itp.tu-graz.ac.at/~schnizer

This website contains a link: Course: Introduction into Mathematica.
The access to this link is restricted to susers logging in from the institute and from the computer room.