Child pages
  • Octave
Skip to end of metadata
Go to start of metadata


GNU Octave is a high-level language primarily intended for numerical computations. It's commands are in general compatible with those of Matlab. A simple Octave program and an associated submit script are as follows:

Category of Software 
What is Octave

GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with Matlab. It may also be used as a batch-oriented language.

Octave has extensive tools for solving common numerical linear algebra problems, finding the roots of nonlinear equations, integrating ordinary functions, manipulating polynomials, and integrating ordinary differential and differential-algebraic equations. It is easily extensible and customizable via user-defined functions written in Octave's own language, or using dynamically loaded modules written in C++, C, Fortran, or other languages.

Octave is available from

 The Official Octave  Manual  is found at:

How to useFree to use

Sample Code

This example comes from

% plot_direct_pi.m -- Illustrative plot of SMAC algorithm 1.1
% usage:         octave> plot_direct_pi( Ntrials )
% Octave version: 3.0.3

% plot_direct_pi -- run and plot results of direct_pi
function plot_direct_pi( Ntrials )

    [XYin,XYout,pi_estimate] = direct_pi( Ntrials );

    clf;                                             % clear graphics 
    plot(XYin(:,1),XYin(:,2),'ro');                  % inner x,y: red 'o'
    hold on;                                         % use same graph
    plot(XYout(:,1),XYout(:,2),'bx');                % outer x,y: blue 'x'

    axis( [-1 1 -1 1],'square' );                    % graph annotations

    str1 = 'plot\_direct\_pi.m: SMAC Algorithm 1.1';
    str2 = strcat( 'Ntrials=',num2str(Ntrials) );
    str3 = strcat( ', pi\_estimate=',sprintf("%6.4f",pi_estimate) );

    title( strcat( str1, "\n", str2, str3 ));

% direct_pi -- SMAC algorithm 1.1: direct-sampling estimate of pi
%    Ntrials:      number of random points in a square of edge 2 
%    Nhits:        number of trial points in inscribed unit circle
%    TrueFalse: vector of T/F = 1/0 = inside/outside unit circle
% note: Octave fn 'find' gives indices of non-zero elements
function [XYin,XYout,pi_estimate] = direct_pi( Ntrials )

    XY = [ran( Ntrials,-1,1 ), ran( Ntrials,-1,1 )];  % x,y vectors

    TrueFalse = (XY(:,1).^2 + XY(:,2).^2 < 1);        % T/F=1/0 vector

    XYin   = XY( find( TrueFalse), : );               % inner x,y's 
    XYout = XY( find(!TrueFalse), : );                % outer x,y's 

    Nhits = size(XYin,1);
    pi_estimate = 4 * Nhits / Ntrials;                % pi/4 = area ratio

% ran -- use Octave fn 'rand' to get uniform random vector in (a,b)
function randvector = ran( rows,a,b )
        randvector = (b-a)*rand(rows,1) + a;

Note, as this program plots a graph, you must have X11-forwarding enabled on your X-terminal session. See the Access (original) page for more information.


Sample Code
$module load octave
octave:1> plot_direct_pi(1000) 



An Octave MPI toolbox is also available. The following script illustrates how it can be used to run one of the examples which comes with it:

Once-off setup
$module load mptib
To use MPITB you must include contents of $MPITB_HOME/.octaverc in ~/.octaverc
$cp  $MPITB_HOME/.octaverc  ~/.octaverc

#$ -S /bin/sh
#$ -cwd
#$ -pe orte 4
#$ -l h_rt=12:00:00
#$ -l h_vmem=2G
module load mpitb
mpirun -wd $MPITB_HOME/Pi octave -q --eval "Pi(2E7,'r')"

results =
  pi =  3.1416
  err = -2.1094e-13
  time =  1.8360
  • No labels