- an easy way to test programs before writing them in more advanced and complicated computer languages.
- a fast way to develop small models without fighting with bugs that arise from such issues as memory allocation.

octave:1> x=1/sqrt(3);

octave:2> y=atan(x)*180/pi

y=30.000

The above example is a simple trigonometric operation. In the first line, a numeric value is assigned to a variable x. In the second line, the arctan of x is calculated and assigned to y, at the same time being converted to degrees(angles are in radians in Octave). The semicolon (;) at the end of the first line suppresses the output while leaving it out causes the output to be displayed on screen, as done in the second line.

Octave can work with arrays as easily as it does with single numbers.

octave:1> x=0:0.01:pi;

octave:2> y=sin(x);

octave:3> plot(x,y)

Here the first line creates an equally-spaced array that goes from 0 to pi in increments of 0.01. The second line evaluates the sine of all the numbers in the array x and assigns to a new array variable y. Finally, the third line draws a plot of y with respect to x. For plotting, Octave calls another open source program, gnuplot.

In fact, you can do algebra even with matrices :

octave:1> M=rand(3,3);

octave:2> M=M+M';

octave:3> M*=2;

octave:4> M=M.^3;

octave:5> [a,b]=eig(M);

In this example, the rand function creates a 3-by-3 matrix of uniformly distributed random numbers. In the second line, the prime (') operator takes the transpose of the matrix. This is then added to the matrix itself to symmetrize it. The result is then re-assigned to the same variable. In the third line, the entire matrix is simply multiplied by 2 whereas in the fourth line,

Apart from the obvious algebra, arithmetic and trigonometry operations for numbers, vectors and matrices, Octave also offers the following useful features :

- Efficient utility functions : diff, ones, zeros, eye, any, eig, linspace, logspace, real, imag, find and many, many more ...
- Polynomial manipulation : polyval, polyder, polyfit
- Plotting : plot, mesh, contour, bar, hist
- Loops and control expressions : while, for, if, if-elseif-else

*NOTE*that loops are*extremely*slow in Octave. Avoid using loops as much as possible. Instead make use of functions that are specially optimized. You can test the inefficiency of loops by using the tic/toc functions for timing.

__Example__:

octave:1> N=1000000;

octave:2> a=randn(N,1);

octave:3> b=zeros(N,1);

octave:4> tic;for n=2:N

> b(n)=a(n)-a(n-1);

> endfor;toc

ans = 33.922

octave:5> tic;c=diff(a);toc

ans = 0.38571

In the above example, carrying out the same operation (calculating the difference between successive elements of an array) takes about 34 seconds using a loop while with the special diff function, it only takes a fraction of a second. Of course, the numbers are system-dependent and the difference is negligible for small arrays. - Logical operations : &,|,&&,||,==,~=,true,false
- User-defined functions :

__Example__:

octave:1> function out=iseven(in)

> if ( rem(in,2)==0 )

> out=true;

> else

> out=false;

> endif

> endfunction

octave:2> a=iseven(3)

a = 0

octave:3> a=iseven(4)

a = 1

If you find yourself needing the same function over and over again, you can also place it in a file with a ".m" extension and call it with the same syntax as in the above example, for which the file would be called "iseven.m". Functions may return any number of values, which can be of mixed type.

You can read more about Octave on the following pages.

- Home page : href=http://www.gnu.org/software/octave/
- Useful links for matrix algebra : http://www.math.uic.edu/~hanson/mcs471octave.html
- Da Coda Al Fine - claims to be good : http://octave.sourceforge.net/coda/index.html
- Octave force - extensions : http://octave.sourceforge.net
- Giant manual : http://www.gnu.org/software/octave/doc/interpreter/