Octave (language)
   HOME

TheInfoList



OR:

GNU Octave is a scientific programming language for
scientific computing Computational science, also known as scientific computing, technical computing or scientific computation (SC), is a division of science, and more specifically the Computer Sciences, which uses advanced computing capabilities to understand and s ...
and
numerical computation Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of numerical methods t ...
. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementat ...
. It may also be used as a batch-oriented language. As part of the
GNU Project The GNU Project ( ) is a free software, mass collaboration project announced by Richard Stallman on September 27, 1983. Its goal is to give computer users freedom and control in their use of their computers and Computer hardware, computing dev ...
, it is
free software Free software, libre software, libreware sometimes known as freedom-respecting software is computer software distributed open-source license, under terms that allow users to run the software for any purpose as well as to study, change, distribut ...
under the terms of the
GNU General Public License The GNU General Public Licenses (GNU GPL or simply GPL) are a series of widely used free software licenses, or ''copyleft'' licenses, that guarantee end users the freedom to run, study, share, or modify the software. The GPL was the first ...
.


History

The project was conceived around 1988. At first it was intended to be a companion to a chemical reactor design course. Full development was started by John W. Eaton in 1992. The first alpha release dates back to 4 January 1993 and on 17 February 1994 version 1.0 was released. Version 9.2.0 was released on 7 June 2024. The program is named after Octave Levenspiel, a former professor of the principal author. Levenspiel was known for his ability to perform quick
back-of-the-envelope calculation A back-of-the-envelope calculation is a rough calculation, typically jotted down on any available scrap of paper such as an envelope. It is more than a guess but less than an accurate calculation or mathematical proof. The defining characteristic o ...
s.


Development history


Developments

In addition to use on desktops for personal scientific computing, Octave is used in academia and industry. For example, Octave was used on a massive
parallel Parallel may refer to: Mathematics * Parallel (geometry), two lines in the Euclidean plane which never intersect * Parallel (operator), mathematical operation named after the composition of electrical resistance in parallel circuits Science a ...
computer at Pittsburgh Supercomputing Center to find vulnerabilities related to guessing social security numbers. Acceleration with
OpenCL OpenCL (Open Computing Language) is a software framework, framework for writing programs that execute across heterogeneous computing, heterogeneous platforms consisting of central processing units (CPUs), graphics processing units (GPUs), di ...
or
CUDA In computing, CUDA (Compute Unified Device Architecture) is a proprietary parallel computing platform and application programming interface (API) that allows software to use certain types of graphics processing units (GPUs) for accelerated gene ...
is also possible with use of GPUs.


Technical details

* Octave is written in C++ using the
C++ standard library The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the origina ...
. * Octave uses an
interpreter Interpreting is translation from a spoken or signed language into another language, usually in real time to facilitate live communication. It is distinguished from the translation of a written text, which can be more deliberative and make use o ...
to execute the Octave scripting language. * Octave is extensible using dynamically loadable modules. * Octave interpreter has an
OpenGL OpenGL (Open Graphics Library) is a Language-independent specification, cross-language, cross-platform application programming interface (API) for rendering 2D computer graphics, 2D and 3D computer graphics, 3D vector graphics. The API is typic ...
-based graphics engine to create plots, graphs and charts and to save or print them. Alternatively,
gnuplot gnuplot is a command-line and GUI program that can generate two- and three-dimensional plots of functions, data, and data fits. The program runs on all major computers and operating systems (Linux, Unix, Microsoft Windows, macOS, FreeDOS, a ...
can be used for the same purpose. * Octave includes a
graphical user interface A graphical user interface, or GUI, is a form of user interface that allows user (computing), users to human–computer interaction, interact with electronic devices through Graphics, graphical icon (computing), icons and visual indicators such ...
(GUI) in addition to the traditional
command-line interface A command-line interface (CLI) is a means of interacting with software via command (computing), commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user ...
(CLI); see #User interfaces for details.


Octave, the language

The Octave language is an interpreted programming language. It is a
structured programming Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making specific disciplined use of the structured control flow constructs of selection ( if/then/else) and repet ...
language (similar to C) and supports many common
C standard library The C standard library, sometimes referred to as libc, is the standard library for the C (programming language), C programming language, as specified in the ISO C standard.International Organization for Standardization, ISO/International Electrote ...
functions, and also certain
UNIX Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
system calls and functions. However, it does not support passing arguments by reference although function arguments are
copy-on-write Copy-on-write (COW), also called implicit sharing or shadowing, is a resource-management technique used in programming to manage shared data efficiently. Instead of copying data right away when multiple programs use it, the same data is shared ...
to avoid unnecessary duplication. Octave programs consist of a list of function calls or a
script Script may refer to: Writing systems * Script, a distinctive writing system, based on a repertoire of specific elements or symbols, or that repertoire * Script (styles of handwriting) ** Script typeface, a typeface with characteristics of handw ...
. The syntax is
matrix Matrix (: matrices or matrixes) or MATRIX may refer to: Science and mathematics * Matrix (mathematics), a rectangular array of numbers, symbols or expressions * Matrix (logic), part of a formula in prenex normal form * Matrix (biology), the m ...
-based and provides various functions for matrix operations. It supports various
data structure In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
s and allows
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impl ...
. Its syntax is very similar to MATLAB, and careful programming of a script will allow it to run on both Octave and MATLAB. Because Octave is made available under the
GNU General Public License The GNU General Public Licenses (GNU GPL or simply GPL) are a series of widely used free software licenses, or ''copyleft'' licenses, that guarantee end users the freedom to run, study, share, or modify the software. The GPL was the first ...
, it may be freely changed, copied and used. The program runs on
Microsoft Windows Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
and most
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Unix-like A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating system An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
s, including
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
, Android, and
macOS macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
.


Notable features


Command and variable name completion

Typing a TAB character on the command line causes Octave to attempt to complete variable, function, and file names (similar to Bash's
tab completion Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands. Command line interpreters are programs that allow a user to interact with the u ...
). Octave uses the text before the cursor as the initial portion of the name to complete.


Command history

When running interactively, Octave saves the commands typed in an internal buffer so that they can be recalled and edited.


Data structures

Octave includes a limited amount of support for organizing data in structures. In this example, we see a structure with elements , , and , (an integer, an array, and a string, respectively): octave:1> x.a = 1; x.b = , 2; 3, 4 x.c = "string"; octave:2> x.a ans = 1 octave:3> x.b ans = 1 2 3 4 octave:4> x.c ans = string octave:5> x x = scalar structure containing the fields: a = 1 b = 1 2 3 4 c = string


Short-circuit Boolean operators

Octave's && and , , logical
operators Operator may refer to: Mathematics * A symbol indicating a mathematical operation * Logical operator or logical connective in mathematical logic * Operator (mathematics), mapping that acts on elements of a space to produce elements of another ...
are evaluated in a
short-circuit A short circuit (sometimes abbreviated to short or s/c) is an electrical circuit that allows a current to travel along an unintended path with no or very low electrical impedance. This results in an excessive current flowing through the circuit ...
fashion (like the corresponding operators in the C language), in contrast to the element-by-element operators & and , .


Increment and decrement operators

Octave includes the C-like
increment and decrement operators Increment and decrement operators are unary operators that increase or decrease their operand by one. They are commonly found in imperative programming languages. C-like languages feature two versions (pre- and post-) of each operator with ...
++ and -- in both their prefix and postfix forms. Octave also does
augmented assignment Augment or augmentation may refer to: Language *Augment (Indo-European), a syllable added to the beginning of the word in certain Indo-European languages * Augment (Bantu languages), a morpheme that is prefixed to the noun class prefix of nouns ...
, e.g. x += 5.


Unwind-protect

Octave supports a limited form of
exception handling In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
modelled after th
unwind_protect
of
Lisp Lisp (historically LISP, an abbreviation of "list processing") is a family of programming languages with a long history and a distinctive, fully parenthesized Polish notation#Explanation, prefix notation. Originally specified in the late 1950s, ...
. The general form of an unwind_protect block looks like this: unwind_protect body unwind_protect_cleanup cleanup end_unwind_protect As a general rule, GNU Octave recognizes as termination of a given ''block'' either the keyword end (which is compatible with the MATLAB language) or a more specific keyword end''block'' or, in some cases, end_''block''. As a consequence, an unwind_protect block can be terminated either with the keyword end_unwind_protect as in the example, or with the more portable keyword end. The ''cleanup'' part of the block is always executed. In case an exception is raised by the ''body'' part, ''cleanup'' is executed immediately before propagating the exception outside the block unwind_protect. GNU Octave also supports another form of exception handling (compatible with the MATLAB language): try body catch exception_handling end This latter form differs from an unwind_protect block in two ways. First, ''exception_handling'' is only executed when an exception is raised by ''body''. Second, after the execution of ''exception_handling'' the exception is not propagated outside the block (unless a rethrow( lasterror ) statement is explicitly inserted within the ''exception_handling'' code).


Variable-length argument lists

Octave has a mechanism for handling functions that take an unspecified number of arguments without explicit upper limit. To specify a list of zero or more arguments, use the special argument varargin as the last (or only) argument in the list. varargin is a cell array containing all the input arguments. function s = plus (varargin) if (nargin

0) s = 0; else s = varargin + plus (varargin); end end


Variable-length return lists

A function can be set up to return any number of values by using the special return value varargout. For example: function varargout = multiassign (data) for k=1:nargout varargout = data(:,k); end end


C++ integration

It is also possible to execute Octave code directly in a C++ program. For example, here is a code snippet for calling rand( 0,1: #include ... ColumnVector NumRands(2); NumRands(0) = 10; NumRands(1) = 1; octave_value_list f_arg, f_ret; f_arg(0) = octave_value(NumRands); f_ret = feval("rand", f_arg, 1); Matrix unis(f_ret(0).matrix_value()); C and C++ code can be integrated into GNU Octave by creating oct files, or using the MATLAB compatible MEX files.


MATLAB compatibility

Octave has been built with MATLAB compatibility in mind, and shares many features with MATLAB: # Matrices as fundamental data type. # Built-in support for complex numbers. # Powerful built-in math functions and extensive function libraries. # Extensibility in the form of user-defined functions. Octave treats incompatibility with MATLAB as a bug; therefore, it could be considered a
software clone In computing, a clone is computer hardware, hardware or software that is designed to function in exactly the same way as another system. A specific subset of clones are remakes (or remades), which are revivals of old, obsolete, or discontinued p ...
, which does not infringe
software copyright Software copyright is the application of copyright in law to machine-readable software. While many of the legal principles and policy debates concerning software copyright have close parallels in other domains of copyright law, there are a number ...
as per '' Lotus v. Borland'' court case. MATLAB scripts from the
MathWorks The MathWorks, Inc. is an American privately held corporation that specializes in mathematical computing software. Its major products include MATLAB and Simulink, which support data analysis and simulation. History MATLAB was created in the 1 ...
' FileExchange repository in principle are compatible with Octave. However, while they are often provided and uploaded by users under an Octave compatible and proper
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
BSD license BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lic ...
, the FileExchange Terms of use prohibit any usage beside MathWorks'
proprietary {{Short pages monitor