The core portion of Octave is what I called the "engine", in it there are a bunch of simple, built-in functions. Nearly everything else, all the other more complex functions that you might use, are simply script files which execute a series of Octave commands. (Very UNIX-like, where even a simple "ls" - the equivalent to "dir" - is an executable.) For the user, there is no real disadvantage to this setup. There are plenty of advantages, as you can modify or add functions as you wish. In fact, since it is mostly Matlab compatible, you can even move a lot of the Matlab ".m" files over with some modifications. (Octave also uses the ".m" extension.)
Everything comes in a .ZIP file. Included is an OS/2 command file inst-octave.cmd that will create a desktop folder and program object for you. This is pretty much just a convenience feature, and you can skip running the install script if you wish and just unzip the package into the folder of your choice. (But, be sure to unzip the extra SCRIPTS.ZIP file if you do that.) I recommend you just run the install script.
Unfortunately, this is not quite it. There is a minor little change that most users will want to fix immediately. It is standard in Matlab that it will search in your current directory for any commands that you execute (if it isn't a built in command.) For example, if you have a script called "Generate_Waveform.m", you want to be able to enter the command "Generate_Waveform" on the Octave command line and have that run. However, by default, the current directory is not included in the search path, and the documentation on what to modify is weak. I did manage to figure out how to do it, so I'll save you the trouble of figuring out how.
In your Octave program directory, you need to find the file called "octaverc".
This is usually located in \scripts\startup under your Octave directory.
In this file, edit the line that starts with LOADPATH = sprintf... and add
the current directory into the search path. For example, I have mine modified
to read:
LOADPATH = sprintf ("%s/scripts//;%s/dlfcn/examples;./", oct_home, oct_home);
No, that's not a typo. oct_home is repeated twice for some reason. If not, it will not be able to search all the script sub-directories. Save the file and re-start Octave. This will make the change take effect and your current working directory will now be searched first for any script files.
That's enough to setup Octave itself, and it's ready to be used. However, it is highly recommended that you also install gnuplot, as Octave does not have any plotting capabilities by itself and relies on gnuplot for this purpose. gnuplot is also freely available (you can download it from here (ftp://ftp.ucc.ie/pub/gnuplot/), or see the previous OS/2 eZine article on gnuplot (http://www.os2ezine.com/20020616/page_5.html)) and installation consists of unzipping it into the directory of your choice and adding that path to your PATH= statement in the CONFIG.SYS file.
That's it. Very plain and spartan. If you have never used such a program before, do not under-estimate its power! Matlab users will feel right at home and know what to expect.
If you don't know what to do, try typing "help". This will generate a very lengthy list of available commands. If you see a command that you want further information on, (e.g. polyfit.m), you can explicitly ask for help on that function by typing "help polyfit". Yes, this is primitive, and there is only a very basic search capability ... so yes, this is just like Matlab. (Actually, the very latest version includes a help search facility now, but this is very recent.)
The command prompt can also be customized, but by default, it numbers your commands for you so you can keep track of it, if you wish. As with the OS/2 command prompt, pressing the up and down arrow keys will scroll through your command history. In an improvement, it actually has command-line completion using the TAB key. So, if you had a function or a variable called "frequency", all you have to do is type "freq" and hit the TAB key and it will attempt to complete the command for you. It will work, unless you have a similar command like "freq_range", in which case, it would stop at the point where the commands differed.
This command will generate a vector called "t" (keep in mind Octave is case sensitive, "t" is not the same as "T") starting from 1 and ending at 100 in steps of 1. So, you'll get a sequence of integers from 1 to 100. The last semi-colon at the end is not strictly necessary, but this instructs Octave to not print out the results of the command. If you had left this out, no harm done, but you'll scroll through a couple of pages listing all 100 elements of "t". If you have a 10,000 element vector, this will be painful. You need to press Ctrl-Break to stop the listing (but Ctrl-C does not work.)
You can also get a bit tricky with this command.
f = 1:(N-1)/100:N/2;
This will generate a sequence of numbers called "f" which starts from 1, ends at N/2 (assuming you have defined a value for "N") in steps of size equal to (N-1)/100.
Now that you have something to work with, you can generate more complicated
data.
sig1 = sin(2*pi*0.1*t);
The above command will generate another sequence of numbers called "sig1" which is a sinusoidal function of "t". Note that "pi" is a constant known to Octave, and is what you expect it to be, 3.14159265....., but, be warned, Octave will let you assign just about anything, and if you're not careful, you can make pi = 10; if you wish!
Well, all that number work is very nice, but not worth a lot unless you can see what's going
on!
plot(t,sig1);
will generate a plot an x-y line plot of your function "sig1" vs. "t". It is possible to just plot "sig1", this would generate exactly the same plot, except the x-axis is labelled with the point number, and not a time value.
As with nearly all commands, plot will accept more than just the default
arguments.
plot(t,sig1,"3+");
This will plot the same function as above, but use colour 3 (which happens to be green) and points which look like "+" instead of a connected line.
If you want to get more tricky, try:
SIG1_real = real(fftshift(fft(sig1)));
This command will return the real component of the Fourier transform of "sig1", which has been shifted so that zero frequency is in the center. (If you have an audio signal, this is how you would extract the frequency spectrum.) There are many other more complicated functions available (e.g. Bessel functions, polynomial fitting, image codecs, audio processing, etc), far too many for me to go into detail.
[pic, cmap] = loadimage("/images/flag.bmp","bmp");
This will load up a .BMP file and separate the image and colour map into the two variables "pic" and "cmap", respectively. Note that the full path seems to be required to load the image, even if it is in the current directory. (Also, you'll need to check what format .BMP it is. I believe it is OS/2 format, since the codec is appears to be provided by Klaus Gebhardt, the fellow who did the OS/2 port.) The argument "bmp" tells it which type of image file it is, and it is case-sensitive and requires the quotes enclosing it. But, one major weakness is that it depends on having an X-Window system and xloadimage in order to do this, which probably rules out OS/2 for now (unless you are running XFree86/2 or some other X server.) However, all functions still "work", and you can save the image to several formats. This brings up the possibility of doing batch image processing with Octave. Just write a script to load up the images, do some manipulation on them, and write them back out.
If you wanted to make a command for linear regression, you could simply create a file called "regress.m" and every time you typed "regress" in Octave, it would execute that script. Actually, it doesn't have to just be a series of commands, you could make it a function, a custom command that required arguments so that you would have to enter "regress(x,Y);" for example. This is, in fact, how all the functions for Octave are implemented. And this is also why the help system is so... let's just say under-developed.
When you ask for help on a command, for example "help plot", Octave looks in all its known paths for the file "plot.m". It then extracts the comments at the beginning of that file to deliver the help. So, if you create your own custom function and don't add those comments, there will be no help presented!
If for some reason you really need to have a compiled C program instead of running in Octave, you're free to make use of the source code and compile your own. There is a help file detailing the available functions and how to call them. You'll need to grab the source code packages if you want to do this. The default binaries-only package just comes with some image codecs in C++. I would generally recommend against this (unless you are using the routines for some other purpose), as the speed of Octave is going to be fairly competitive with your C program that most users can generate, and you will spend far less time debugging your Octave script than your C program. As one professor put it to me (he used FORTRAN), "I used to spend days programming and debugging, now I do this in hours!". He, as have many others, realized that his job wasn't to program, but to do something else (in his case, astronomy), so it was far better to expend his effort and brain power on his field than programming, which was simply a vehicle to get him where he's going. Programming was not a competitive advantage, but that's a rant for another day.
If one really needs Matlab compatibility, the included documentation (in traditional OS/2 .INF format) includes a section detailing how to setup Octave for maximum compatibility.
If, like me, you're on a tight budget, you can also take a look at Euler for OS/2 (http://hobbes.nmsu.edu/cgi-bin/h-browse?sh=1&dir=//pub/os2/apps/math/euler), the latest package which some kind soul has compiled and uploaded as of April 2002. The packages are freely available from hobbes (http://hobbes.nmsu.edu), and you can find out more at Euler's Home Page (http://mathsrv.ku-eichstaett.de/MGF/homes/grothmann/euler/). Like Octave, Euler is released under GPL, so it is open-source. The author specifically states that Euler is not a Matlab clone, however, the command syntax and environment is very similar. It also includes its own plotting routines, so it might be worth checking out if similarity to Matlab is not a concern.
I hope that this mini-review has given you an idea of what Octave can do, but more generally, what you can do with OS/2!
This article is courtesy of www.os2ezine.com. You can view it online at http://www.os2ezine.com/20020716/page_5.html.