Octave
From the official website:
- GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments. It also provides extensive graphics capabilities for data visualization and manipulation. Octave is normally used through its interactive command line interface, but it can also be used to write non-interactive programs. The Octave language is quite similar to Matlab so that most programs are easily portable.
Installation
Run the GUI with octave --gui
or the CLI with octave-cli
.
Alternative graphical interfaces
The default octave GUI is included in the octave package. Alternatively, you can use one of the following unofficial GUIs:
- Cantor — A graphical user interface that delegates its mathematical operations to one of several back ends (Scilab, Maxima, Octave and others).
- JupyterLab — Browser-based interactive environment which supports many programming backends, including Octave.
Performance
Octave uses the blas package for linear algebra computation by default. However, this implementation does not take advantage of modern CPU instructions. To accelerate performance, the blas-openblas package can be installed as a drop-in replacement for blas. Other BLAS implementations can also be used depending on available hardware, such as intel-oneapi-mkl for Intel CPUs or cuda for NVIDIA GPUs.
To illustrate this point, the following code can be used to get an estimate for how many GFLOPS are being executed on an NxN matrix multiply:
N = 4096; A = single(rand(N, N)); B = single(rand(N, N)); start = clock(); C = A * B; elapsedTime = etime(clock(), start); gFlops = 2 * N * N * N / (elapsedTime * 1e9)
Running the following code on an Intel Core i7-9750H:
octave ~/test_program.m
gFlops = 3.7222
After installing openblas and running the program on a single thread:
OMP_NUM_THREADS=1 octave ~/test_program.m
gFlops = 121.55
After letting openblas use all 12 threads available on the 9750H:
OMP_NUM_THREADS=12 octave ~/test_program.m
gFlops = 281.33
Octave-Forge
Octave provides a set of packages, similar to Matlab's Toolboxes, through Octave-Forge. The complete list of packages is here.
Packages can be installed #Using Octave's installer or #Using the AUR.
Using Octave's installer
Packages can be managed using Octave's installer. They are installed to ~/octave, or in a system directory with the -global option. To install a package:
octave:1> pkg install -forge packagename
control
, need the gcc-fortran Arch Linux's package in order to compile and install.To uninstall a package:
octave:3> pkg uninstall packagename
Some packages get loaded automatically by Octave, for those which do not:
octave:4> pkg load packagename
Loading all packages is discouraged, as it may affect performance and create name conflicts. If you however wish to load all packages, you can issue:
octave:5> cellfun (@(x) pkg ("load", x.name), pkg ("list"));
To see which packages have been loaded use pkg list
, the packages with an asterisk are the ones that are already loaded.
A way to make sure that all packages gets loaded at Octave startup:
/usr/share/octave/site/m/startup/octaverc
## System-wide startup file for Octave. ## ## This file should contain any commands that should be executed each ## time Octave starts for every user at this site. pkg load all
Using the AUR
Some packages may be found in the AUR (search packages). New Octave-forge packages for Arch can be created semi-automatically using the Octave-forge helper scripts for Arch Linux.
Plotting
Qt is the default plotting backend:
>> available_graphics_toolkits ans = { [1,1] = fltk [1,2] = qt } >> graphics_toolkit ans = qt
Alternatively you can use either FLTK or Gnuplot backend (by installing gnuplot) and running the following command:
>> graphics_toolkit("gnuplot");
To make this change permanent add it to your ~/.octaverc
file.
Reading Microsoft Excel Spreadsheets
You can open .ods
, .xls
and .xlsx
files with the odsread
or xlsread
function, which requires the octave-ioAUR package:
octave:1> odsread('myfile.ods'); octave:1> xlsread('myfile.xls'); octave:1> xlsread('myfile.xlsx');
Converting to CSV format
Alternatively, first convert the files to .csv
using LibreOffice Calc (limited to 1024 columns) or Calligra Sheets (calligra, limited to 32768 columns).
After the conversion is complete you can use the build-in Octave function csvread
for .csv
files:
octave:1> csvread('myfile.csv');
Troubleshooting
Zsh Undecodable Token
If you get error
undecodable token: b(hex)[23m
when printing, install grml-zsh-config and relogin.
vi Mode Undecodable Token
Users with their .inputrc
configured for vi-mode, for example, as
~/.inputrc
$include /etc/inputrc set editing-mode vi $if mode=vi set show-mode-in-prompt on set vi-ins-mode-string \1\e[6 q\2 set vi-cmd-mode-string \1\e[2 q\2 set keymap vi-command # these are for vi-command mode Control-l: clear-screen Control-a: beginning-of-line set keymap vi-insert # these are for vi-insert mode Control-l: clear-screen Control-a: beginning-of-line $endif
may have the Octave GUI prompt corrupted as q>> undecodable token: \001b(hex)[6\0020(hex)
.
To remedy this, disable the show-mode-in-prompt
setting for Octave, by changing the above .inputrc
to be
~/.inputrc
$include /etc/inputrc set editing-mode vi $if mode=vi $if Octave set show-mode-in-prompt off $else set show-mode-in-prompt on set vi-ins-mode-string \1\e[6 q\2 set vi-cmd-mode-string \1\e[2 q\2 set keymap vi-command # these are for vi-command mode Control-l: clear-screen Control-a: beginning-of-line set keymap vi-insert # these are for vi-insert mode Control-l: clear-screen Control-a: beginning-of-line $endif $endif