**Introduction**

Octave is a free (both free as in beer and free as in speech) MATLAB compatible numerical programming tool available under the GNU General Public License. MATLAB, an abbreviation for “Matrix Laboratory”, is currently the most widely used commercial, proprietary numerical programming tool. Even a single license for the MATLAB software is a substantial cost. MATLAB is essentially a scripting language similar to Perl, Python, or PHP with a comprehensive, highly integrated set of numerical, statistical, mathematical, and graphical functions including, for example, the Fourier transform, matrix inversion, and histograms. In part because MATLAB has become the de facto industry standard for numerical programming, Octave is of particular interest to individuals, companies, and organizations engaged in numerical and mathematical programming and research and development.

**A Little Bit About MATLAB**

MATLAB was originally developed in the 1970’s as an easy-to-use interactive front-end for recently developed Fortran libraries of matrix algebra and matrix manipulation functions. For this reason, MATLAB was originally designed around two-dimensional matrices of real numbers. In the 1980’s, MATLAB was rewritten in the then popular C programming language and converted into a commercial software product from MathWorks. Over the years, MATLAB has been extended to support multi-dimensional numerical arrays, character strings, many kinds of mathematics beyond matrix and linear algebra, object-oriented programming, and many other features. MATLAB has a number of good features, but it is also a hodge-podge of features added by many different programmers at MathWorks over the last 30 years.

**Octave**

Octave was developed by John W. Eaton and others as a free clone of MATLAB. Octave shares most of the syntax and features of MATLAB. For a wide range of mathematical and numerical programming tasks, Octave is excellent and can do everything MATLAB can do. It is available as both source code and pre-compiled binaries for the Microsoft Windows, Mac OS X, and Linux/Unix platforms. Octave can be easily downloaded from the Octave web site: https://www.gnu.org/software/octave/

Octave and MATLAB have almost identical syntax. There is extensive information on the Web about MATLAB and Octave as well as many books about MATLAB. This article will focus on certain specific issues and features deemed especially important in adopting or using Octave for numerical and mathematically oriented projects. For detailed information on the syntax, readers are referred to the extensive and excellent on-line and published documentation.

**Example 1: Adding Two Vectors in Octave**

octave-3.2.4.exe:10> a = [1 2 3] a = 1 2 3

octave-3.2.4.exe:11> b = [4 5 6] b = 4 5 6

octave-3.2.4.exe:12> a + b ans = 5 7 9

**Example 2: A Numerical Range in Octave**

octave-3.2.4.exe:13> 5:10 ans = 5 6 7 8 9 10

**Example 3: A Simple Plot**

octave-3.2.4.exe:15> a = 1:100; octave-3.2.4.exe:16> pi ans = 3.1416 octave-3.2.4.exe:17> data = sin(2*pi*a/20); octave-3.2.4.exe:18> plot(data)

Octave includes built-in functions to read and write human readable tab-delimited and comma separated values (CSV) data files. In this day and age, most computer programs ranging from databases to spreadsheets to word processors can easily read and write data files in tab-delimited or comma separated value formats. Almost all computer programming languages can easily read and write tab-delimited data files and, with somewhat more work, comma separated value data files. The Octave built-in functions for this are: *dlmread*, *dlmwrite*, *csvread*, and *csvwrite*. In real world projects, it is actually rare to use Octave or similar tools fully standalone. One is usually importing data from other programs and exporting data to other programs. With huge disk drives and powerful modern computer networks, it is nearly always possible to use human readable tab-delimited or comma separated value data files to import, export, and share data. This is often the most convenient way to integrate Octave with other tools. In addition, Octave can read and write binary data, for example through C style built-in *fopen*, *fread*, *fwrite*, and *fclose *functions.

Octave’s support for common multimedia and binary file formats in somewhat limited but adequate. Octave can read and write a number of binary image file formats using its *imread *and *imwrite *functions. The author works a great deal with digital audio, including audio special effects and speech recognition. Octave can read and write the widely used Microsoft WAV (Wave) audio file format using the *wavread *and *wavwrite *functions. Uncompressed wave audio files are quite simple and can be easily read and written at a low level by almost any programming language as well as many common audio processing tools on all of the major computer operating systems: Microsoft Windows goes without saying, both Mac OS and the iPhone iOS support wave files, and many variants of Linux and Unix. The popular free (as in beer, as in speech) Audacity audio processing program can both read and write uncompressed WAV audio files; Audacity is available as both source code and pre-compiled binaries for Windows, Mac, and Linux platforms.

Octave is quite fast. The basic data type of Octave is a “matrix,” which now means a multi-dimensional array of double precision floating point numbers. Today, there is rarely a substantial difference in speed between single and double precision floating point arithmetic on most platforms. The various matrix operations built into Octave are very close in speed to fast compiled code. Because its basic data type is basically a multi-dimensional array of native data types (double precision floating point) Octave (and MATLAB) can generally perform faster on numerical programming tasks than list-based symbolic manipulation programs such as Mathematica. Octave also supports a simple mechanism to add fast compiled C functions to Octave through its *mkoctfile *function/command:

mkoctfile [-options] file ...

The mkoctfile function compiles source code written in C, C++, or Fortran. Depending on the options used with mkoctfile, the compiled code can be called within Octave or can be used as a stand-alone application. mkoctfile can be called from the shell prompt or from the Octave prompt.

Because Octave is free and available for download on all major computer platforms, it is now easy to create mathematical or numerical scripts to share with anyone on these platforms (MS Windows, Mac OS X, or Linux/Unix) without the huge cost of the MATLAB program.

**Caveats**

While Octave has very extensive features — few users will need more — Octave does not support all of the advanced and recent features of MATLAB. While Octave is free, it is licensed under the GNU General Public License (GPL), rather than the Berkeley style licenses that allow users to incorporate source code into their proprietary commericial programs. The GPL is sometimes a problem for commercial users of Octave or other free software. Octave error messages can be cryptic.

Both Octave and MATLAB have little support for symbolic manipulation. In many areas such as signal and image processing, this is rarely a concern. The author has used the free Maxima (formerly MACSYMA) program successfully for symbolic manipulation tasks that Octave could not perform.

**Alternatives**

There are many free and other not-so-free numerical, mathematical, and symbolic programming tools including MATLAB, Mathematica, MAPLE, Sage, Python/NumPy, Axiom, Maxima, and many others. Interested readers are referred to many online sources and discussions for a comprehensive list of alternatives. The special advantages of Octave are that it is mature software, has a large user base, is free, is available in both source code and pre-compiled binaries for all three major computer platforms, and is mostly compatible with MATLAB, which has become the de facto industry standard for numerical programming in recent years.

**Conclusion**

For many uses and users, Octave is an excellent alternative to MATLAB or an excellent complement to MATLAB. Some users may find that they will want one licensed copy of MATLAB to make sure their scripts will run under standard MATLAB while using Octave on all of their computers to save costs and to ensure their scripts can be run by anyone, anywhere at no cost using the free Octave tool. Many users will be glad to entirely save the considerable cost of MATLAB, no small amount especially in the current difficult economy.

© 2011 John F. McGowan

**About the Author**

*John F. McGowan, Ph.D. * is a software developer, research scientist, and consultant. He works primarily in the area of complex algorithms that embody advanced mathematical and logical concepts, including speech recognition and video compression technologies. He has extensive experience developing software in C, C++, Visual Basic, Mathematica, MATLAB, and many other programming languages. He is probably best known for his AVI Overview, an Internet FAQ (Frequently Asked Questions) on the Microsoft AVI (Audio Video Interleave) file format. He has worked as a contractor at NASA Ames Research Center involved in the research and development of image and video processing algorithms and technology. He has published articles on the origin and evolution of life, the exploration of Mars (anticipating the discovery of methane on Mars), and cheap access to space. He has a Ph.D. in physics from the University of Illinois at Urbana-Champaign and a B.S. in physics from the California Institute of Technology (Caltech). He can be reached at [email protected].

**Recommended Octave books**

**Sponsor’s message**: Check out Math Better Explained, an elegant and insightful ebook and set of screencasts that will help you see math in a new light and experience more of those awesome “aha!” moments when ideas suddenly click.

I’m fortunate to be attending a university that provides MATLAB licenses to students at no charge. However, I find that on my Mac at least, MATLAB is very slow to load and has a rather clunky interface. I end up doing most of my work in the Terminal with Octave because it’s faster.

My numerical analysis professor also prefers Octave, so working in Octave avoids syntax errors that may occur in switching between Octave and MATLAB.

This wiki lists some of the differences in syntax between the two systems.

https://bit.ly/94OBgu (wikibooks.org)

Insightful comment, Tony. Thanks for stopping by.

Scilab?

Excellent program as well, but it doesn’t try to be MATLAB-compatible (and up until not too long ago, it wasn’t truly FOSS). Depending on your needs, being able to run virtually unchanged MATLAB code may or may not be a deal breaker.

As stated, there are some things that don’t work in both MATLAB and in Octave. I was a huge Octave fan (and still do support the effort) until I had to take a spectral methods course using a book from Nick Trefethen … nearly all of his codes were unusable on Octave as-is.

I encourage people to use Octave until it doesn’t work for you, then complain to Octave folk to fix, then last resort get MATLAB.

There is an alternative to complaining to the Octave developers and switching to MATLAB that you didn’t mention: you can help us. John W. Eaton released it under the GPL because he doesn’t consider Octave to be a charity; he considers it a collaboration. We’re not doing this because we are here to serve you; we are doing it because we want to work together with you, to collaborate freely without restrictive license agreements, because we believe that academic freedom requires software freedom.

I should start writing a few pointers on how to get started with Octave development. I wasn’t born either knowing how to hack on Octave, but I do it for the reasons mentioned above.

You and Doug (below) are both correct in my stating that one should not complain to the developers. However, one must admit that users of Octave quite possibly don’t have the background to properly implement some things properly. Or perhaps, they don’t have the time.

However, you are both correct and I apologize for my blanket statement.

Time is never had, only made. And skills can always be acquired. 🙂

Complaining to the developers is fine. We get lots of complaints, many of them quite insightful. Just don’t think it’s your only option.

Andrew!! you should not say ” complain to octave folk” — you should say ” it is open source so you can help to improve octave, and make it do what you want”.

John, a small point. Octave’s goal is not to be a MATLAB clone, and lead dev jwe didn’t set out to create one either. Octave started as companion software to a chemical reactor textbook, as a thin wrapper of Fortran libraries, much like MATLAB. Due to the vagaries of fate, the MATLAB developers decided to close it up early in its lifetime and jwe decided to keep it free. Later on Octave’s users started to request MATLAB compatibility and so it was added little by little, until in recent years it became an explicit goal.

Notice that compatibility is a goal, not cloning, and we generally understand this to mean that MATLAB code should run in Octave. We don’t mind if Octave implements more features that MATLAB doesn’t, and we are not trying to replicate all of MATLAB’s cosmetic features, and we intentionally avoid some of its bugs unless we see that users depend on the buggy behaviour.

Here is a good link to jwe talking about why and how Octave and many other interesting things about it, straight from the horse’s mouth:

https://videolectures.net/mloss08_eaton_oct/

> The GPL is sometimes a problem for commercial users of Octave or other free software.

obligatory-GPL-nitpicking:

GPL is never a problem for users. The GPL is a problem for developers who might want to extend Octave and then close off the source code and then themselves pose a problem for users of the extended Octave. But that is OK, since the GPL is designed to pose a problem for code closers. Thanks for reading.

/obligatory-GPL-nitpicking

1. How does it compare to “R”.

https://goo.gl/YBOWb

2. Can it do 3D graphs?

I was considering Matlab for EASY 3D graphs, but perhaps I should look at Octave…

Hello Jim,

Octave uses GNUplot for graphics. GNUPlot is automatically installed with Octave. Octave can do 3D as well as 2D plots. Here is an example Octave code for a 3D plot:

x = -3:0.1:3;

[xx,yy] = meshgrid(x,x);

z = exp(-xx.^2-yy.^2);

figure, mesh(x,x,z);

title('exp(-x^2-y^2)');

Sincerely,

John

Hello Jim,

I am not familiar with “R”. I know it is reputed to have very extensive statistical features, so I suspect for some advanced and specialized areas of statistics, it has more features than Octave.

Octave has many built in statistical functions:

https://www.network-theory.co.uk/docs/octave3/octave_229.html

Click on the next Link in the lower left corner of the on line reference manual above to step through Chapter 24 on the statistics functions in Octave. It gives a list of the built-in statistics functions and what they do.

Sincerely,

John

You wrote, “Both Octave and MATLAB have little support for symbolic manipulation”. In such situations I just put (Object-Oriented) Ruby code together, that produces (here) Octave code, runs it through Octave, and works with the result.

Cheers,

Stephan

Stephan, the author is not referring to the structured nature of the code, but rather to symbolic manipulation in the mathematical sense (e.g., integrating analytically like a CAS does, not numerically).

MATLAB does offer symbolic manipulation through the Symbolic Toolbox which provides a Maple-like worksheet interface. The symbolic support in the base MATLAB and Octave is there, but limited compared to a package like Maple, as mentioned in the article.

https://www.scilab.org is the missing elephant on the list. In my experience scilab is more mature and full featured than octave.

Completely open source, under active development and used by multiple public and private entities.

Very young, but very interested project https://mathete.com

It`s WAS – Web Algebra System. All calculations in browsers only and document may be publication.

Looks very pretty https://www.youtube.com/watch?v=SuuVi9AjZAY

The Simulink graphical user interface is quite handy for Matlab beginners, yet Octave does not support it. Is there any guide or example available that shows how to convert Simulink models to Octave? In my special case it’s a dynamic helicopter model and as far as I understand it should be possible to cast the solution of the differential equation that Simulink carries out into a form that makes it possible to use one of Octaves solvers for the time integration.

Thanks,

Juergen

If you don’t care about MATLAB compatibility, my first choice for numerical computation (especially graphics) would be Python. Matplotlib package offers a MATLAB-like syntax for 2-D plots (https://matplotlib.sourceforge.net/) and the community around python is much more active than around octave. One of the main reasons for giving up on Octave was the fact that there are still many bugs and little support from the community.

Fortran, C++ ….uhhh… Time to start a C# Matlab alternative.

There is no clone for Simulink on octave yet. Matlab’s clone in terms of GUI is already exists

guioctave

and

Xoctave.

I prefer Xoctave over guioctave since it is stable and well maintined.

There is also online version of Octave – https://octave.im/

I am an Extra Class ham radio enthusiast, whi is looking at a review in this months QST (July) and if it can be done on my Samsung 5.0 lollipop android zmart phone thats where its done.

The book review of Ten Essential Skills for Electrical Engineers suggest obtaining MATLAB software, but some commentary suggust the free version of Octave would wofk just as well. I run Windows 8.1 Professional, with Ubuntu access but again prefer the S5 in Android.

So what about Android. Tnx Bruce, k3myi