Course in OctaveDuration: 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. Exercises (in Norwegian) in the field of systems theory of dynamic systems. About OctaveStarting OctaveWhat is on the Start / GNU Octave menu? We start Octave from the Start menu. The command window with the command lineWe 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. WorkspaceAll variables generated during the session are stored in the workspace. The workspace is cleared when you quit Octave. We try a few commands:
Hjelp!Command line help: help command. Example:
Functional overview: http://octave.sourceforge.net/index/index.html Manual: http://www.octave.org/doc/octave_toc.html ScriptsAn 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. Example:
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) operationsCreating matrices. Getting matrix information:
Special matrices:
Matrix calculations:Matrices can be used in matrix calculations. A few examples:
Elementwise calculations:Example:
PlottingIntroductionPlots 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 plotThe 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 commandsHere are a few plot utility commands (try):
Plot editing commands and optionsHere is an example showing several useful plot editing commands and options:
Taking screen-shots of graphsThere 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. Function PackagesMany function packages are included in Octave, see http://octave.sourceforge.net/index/index.html 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):
September 28 2004. Finn Haugen (finn.haugen@hit.no)
|