Octave (Matlab clone)Table of contents 1 IntroductionThe Octave software claims to be mostly compatible with Matlab; and this seems an accurate statement. 2 Installation2.1 MS WindowsFor MS Windows, download the latest version from http://sourceforge.net/project/showfiles.php?group_id=2888&package_id=40078. The latest version in January 2009 was 3.0.3, so you would download and execute octave-3.0.3-setup.exe. This is an executable file which will install Octave on your machine. You need to answer a few questions:
2.2 Mac OS XBasic octave installation on Mac OS X:
This file is disk image, from which (once you have mounted them by double clicking on the dmg file) you can drag the octave (and Gnuplot) application into the application folder. 2.3 Linux/UnixOne can either download the source files (ending in .tar.gz or .tar.bz2) and compile from those (if you know how to do that). However, typically the package management for the linux distribution you are using does provides the octave software. 3 How do I start Octave?On the University machines, the software should be located in Start->All Programs->Your School Software->Engineering Sciences->Octave. If you only get a prompt (i.e. a mostly blank window with a blinking prompt), then type octave and press return. This will start octave. 4 Octave/Matlab compatibility issuesThis section lists situations/commands where Octave behaves significantly different from Matlab and where this is relevant for the learning and teaching of Matlab at the School of Engineering Sciences. Students are invited to report incompatibility issues not listed here (by email to fangohr@soton.ac.uk). 4.1 General observations4.1.1 WindowsI have done a few tests (creation of vectors, plotting of x and against y-vector, check that ode45 command exists) with version 3.0 on MS Windows, and Octave seems to behave exactly like Matlab (although the ouput displayed on screen sometimes has a slightly different format). Hints:
4.1.2 Mac OS XThe version I have tried on a Mac OS X system (although having the same version number 3.0.0) did by default not have the octave package odepkg installed and did therefore not know about the ode45 command (but has alternative commands such as lsode that we can use instead). All octave packages can be downloaded from http://octave.sourceforge.net/packages.html and installed with pkg install FILENAME (see octave web pages for further instructions). 4.1.3 Linux/UnixThere is of course octave for Linux (originally, Octave was developed on Unix/Linux and only later ported to Windows and Mac OS X). 4.2 ODE45 - function handleThe ode45 function in Matlab can be called like this: [x,y]=ode45('rhs',[0,2],1); or like this: [x,y]=ode45(@rhs,[0,2],1); The first version passes the function name rhs as a string to the ode45 function, the other one as a handle. Octave only supports the second option, so in Octave the corresponding command has to read: [x,y]=ode45(@rhs,[0,2],1); 4.3 ODE45 - default accuracyMatlab's default settings for allowed absolute and relative error tolerances (and related to that step size in the integration) differ from Octave's. Octave has a larger step size. To reduce this, one can use the following settings
[Tested with octave GNU Octave, version 3.0.3 on Mac OS X] 4.4 Editing m-filesA student reports that on Mac OS X, they cannot type edit myfile.m to open an editor to edit the file. The edit command (in Matlab) will start an editor instructing it to load the file myfile.m if it exists, or creating an empty file and loading it into the editor if the file does not yet exist. The default editor is part of the MATLAB Graphical User Interface. As there is no such GUI for Octave, the edit command in Octave (on any operating system) is likely to try to invoke the default editor that has been defined. On Unix (this includes Linux and Mac OS X), it is common to set an environment variable with name EDITOR to contain the name of the desired editor. If you find that the edit myfile.m command does not work satisfactorily, the simplest work around is not to use it. Instead you can open the m-file directly in some text editor of your choice. You need to make sure you save the file myfile.m, before you execute the file by either typing myfile at the Octave prompt, or calling myfile() if myfile.m contains a function. You need to make sure the octave program is in the same working directory as the file. You can use the commands pwd (Print Working Directory) in octave to display the current directory and cd to Change Directory: octave:1> pwd ans = /Users/fangohr octave:2> cd tmp octave:3> pwd ans = /Users/fangohr/tmp octave:4> cd .. octave:5> pwd ans = /Users/fangohr octave:6> Any plain text editor will do. On all platforms Emacs is available (although it might need some getting used to): We recommend XEmacs for Windows, Emacs or XEmacs for Linux and Aquamacs for Mac OS X. All of these support syntax highlighting for matlab files (and also for LaTeX files). Another often used cross-platform editor is VIM. You can also use Textedit on Mac OS X (which is very basic but comes with Mac OS X preinstalled), edit on Windows (which is even more basic) or any other source code text editor (see list of these on Wikipedia entry for Source code editor). 4.5 Further resourcesSee also FAQ on Matlab compatibility at http://wiki.octave.org/FAQ#Differences_between_Octave_and_Matlab and this Wiki entry http://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB |
|||