Course in Octave
Duration: Approximately 2 hours (2 *45 min).
Note: Octave is very similar to Matlab, so this course will also serve as a course in Matlab. However, the user interface in Matlab is richer than in Octave.
What is on the Start / GNU Octave menu?
We start Octave from the Start menu.
The command window with the command line
We try the following simple commands from the command line (the command are executed by pressing Enter):
Octave functions are vectorized, i.e. functions can be called with vectorial arguments.
Note: Windows Paste works in the command window using the Shift + Insert buttons.
All variables generated during the session are stored in the workspace. The workspace is cleared when you quit Octave. We try a few commands:
Command line help: help command. Example:
Functional overview: http://octave.sourceforge.net/index/index.html
An Octave script is a text file of name *.m containing Octave expressions. You can edit the script using any text editor, e.g. Notepad.
You run the script by typing the script name (without the file extension m) on the command line, causing all the expressions to be execued automatically as if they were written on the command line individually.
You should use scripts even for small tasks.
Do not use script names that are existing variables, commands or function names.
C:\Programfiler\GNU Octave 2.1.50\octave_files is the default current directory which is the directory where Octave looks for your scripts and functions (i.e., you m-files). To display the name of the current directory from within Octave, type
Several directory commands are available:
If your files are stored in a directory - say dir1 - different from the current directory, you can include dir1 in the search directory path of Octave by using the addpath command.
Matrix (or array) operations
Creating matrices. Getting matrix information:
Matrices can be used in matrix calculations. A few examples:
Plots are generated with the plotting package Gnuplot. Plotting commands are automatically transferred to Gnuplot commands. A Gnuplot window is opened in the background.
Gnuplot may be a little ackward in the beginning, but behaves well if you do the following:
Plotting with plot
The basic plotting command is plot. An example:
To add information to the plot, execute the command followed by the replot command (on the Octave command line). Example:
Useful utility commands
Here are a few plot utility commands (try):
Plot editing commands and options
Here is an example showing several useful plot editing commands and options:
Taking screen-shots of graphs
There are options of the print command for sending plots to a printer or to a graphics file (check the print command in the functions overview), but I have a little bad experience with the print command in this context (the graphics files does not look as expected ). Alternatively, you can simply press
This copies the graph window to the Windows clipboard, for pasting into Windows programs, as Paint, Paint Shop Pro, Word etc. There you may add lines and text to the graph (you may alternatively add text using the text function). Then save to file or send to printer.
Many function packages are included in Octave, see
We browse the Control Theory package.
Example: Simulating the step response of a mass-spring-damper system (step in the applied force, and the response in the position is simulated):
The transfer function from F to y is
y(s)/F(s) = 1/(ms2+Ds+K)
Octave-script (name it e.g. mfdsim.m):