Help to Log, Save and Edit Octave Sessionsin MathLab

Instructions for Octave on the MathLab NeXT machines in room 200 SEO.
(Your mileage will vary on other systems.)

Saving Your Octave Session Log to a File and Editing:

• Logging Octave Sessions with Diary Command:

The octave command

diary on
opens a file called diary in your current working directory into which your following octave commands along with prompts and results are saved or logged until you use the octave command

diary off
which stops the logging into the file diary.

• Example of Input and Use:
```mathlab:1> octave
octave:1> diary on
octave:2> function y = f (x)
>
>        y(1) = -2*x(1)^2 + 3*x(1)*x(2)   + 4*sin(x(2)) - 6;
>        y(2) =  3*x(1)^2 - 2*x(1)*x(2)^2 + 3*cos(x(1)) + 4;
>
>      endfunction
octave:3>      [x, info] = fsolve ("f", [1; 2])
x =

0.57983
2.54621

info = 1
octave:4> diary off
octave:5> # more work (caution: this marks a comment)
......
octave:20> quit
mathlab:2>
```

Everything is saved into the file called diary from the statement following the diary on command up to and including the diary off command.

• Alternative Mouse Way to Grab Octave Session Logs:

Note that you can ALSO mark the desired Terminal window contents by
1. dragging the mouse cursor with the right button held down over the contents,
2. click the Copy command in the Terminal/Edit submenu (also the Alt-c key sequence on most keyboards),
3. click on the Edit Icon on the Dock

(if your Icon Dock on the right hand side of the screen does not have the Edit Icon (pencil on a page), ask the lab assistant, or go to the root directory /NextApps, click on the Edit.app file, put the cursor on the icon in NeXT Workspace holding down the mourse right button dragging the icon to the Icon Dock and releasing the button, so that the Edit Icon should permanently reside in the Dock),
4. click the New command on the Edit/File submenu
5. and then click the Paste command on the Edit/Edit submenu (also the Alt-nv key sequence for both New and Paste together).

• Editing Diary Log Files:

You can also edit your diary file to add your name, course and assignment title. The easiest way to edit in MathLab is to
1. find the file diary in the NeXT Workspace (clicking on the NeXT cube at the top of the icon dock on the right) in the current working directory (likely your home directory if you are just starting),
2. double click on the file name diary or its icon there, a NeXT Edit Window should pop up

(if it does not, tell the lab assistant to correct the incorrect default, directing the assistant to the Lab supervisor if the assistant does not know),
3. type your corrections in the Edit window,
4. click on Save As... in the Edit/File submenu (also the Alt-S key sequence) giving the file a new name, like diary.math310hw2,
5. then finally click on the Print selection in the Edit Menu (also the Alt-p key sequence).

• Another Way: Printing Diary Log Files From Terminal Windows:

You can print out the diary file using

lpr diary
(lpr means line printer, but these days should stand for laser printer; you can also use what ever method you usually use in printing out files) from the command line (after quitting octave) using the same the current working directory in the Terminal window in which you typed the octave command.

• Further Hints on Diary Command Use:

The octave diary file custom naming command diary [filename] does work and will just get you stuck.
If you have an existing diary file, you might want to erase (remove) it by the terminal (unix) command

rm diary
or rename (move) the old file by the terminal command

mv diary diary.old
say, otherwise your new octave session will be added onto the old one.

• History Command:

Your octave session or history is automatically saved to the file .octave_hist in your home directory (~/.octave_hist) and the last 20 lines can be listed using the octave command

history 20
for instance, while form

history -q 35
lists the last 35 unnumbered, but in both cases NO octave prompts or octave outputs are included.

Web Source: http://www.math.uic.edu/~hanson/OctaveLogSave.html

Email Comments or Questions to hanson@math.uic.edu