Difference between revisions of "Octave"

From ArchWiki
Jump to: navigation, search
(Octave-Forge: packaging)
(update Pkg/AUR templates (https://github.com/lahwaacz/wiki-scripts/blob/master/update-package-templates.py))
 
(29 intermediate revisions by 16 users not shown)
Line 1: Line 1:
 
[[Category:Mathematics and science]]
 
[[Category:Mathematics and science]]
{{Article summary start}}
+
[[ja:Octave]]
{{Article summary text|This article contains information about the installation, configuration and use of GNU Octave.}}
+
{{Related articles start}}
{{Article summary heading|Related}}
+
{{Related|Matlab}}
{{Article summary wiki|Matlab}}
+
{{Related|Sage-mathematics}}
{{Article summary wiki|Sage-mathematics}}
+
{{Related|Mathematica}}
{{Article summary wiki|Mathematica}}
+
{{Related articles end}}
{{Article summary end}}
+
 
 
From the [http://www.gnu.org/software/octave/ official website]:
 
From the [http://www.gnu.org/software/octave/ official website]:
  
Line 14: Line 14:
 
Octave can be [[Pacman|installed]] with the package {{Pkg|octave}}, available in the [[official repositories]].
 
Octave can be [[Pacman|installed]] with the package {{Pkg|octave}}, available in the [[official repositories]].
  
== Octave-Forge ==
+
{{Note|By default the {{ic|octave}} command provided by this package attempts to run the gui and fails if you haven't installed {{Pkg|qscintilla}}{{Broken package link|package not found}}, which is needed for the gui. To start the command line interface run the {{ic|octave-cli}} command instead.}}
  
Octave provides a set of packages, similar to Matlab's Toolboxes, through [http://octave.sourceforge.net/index.html Octave-Forge]. Some of these packages may be found in the AUR ([https://aur.archlinux.org/packages.php?O=0&K=octave-&do_Search=Go search packages]). A non-exhaustive list:
+
== Octave-Forge ==
* {{App|Image|Provides functions for processing images.|http://octave.sourceforge.net/image/index.html|{{AUR|octave-image}}}}
+
* {{App|Statistics|Provides additional statistical functions.|http://octave.sourceforge.net/statistics/index.html|{{AUR|octave-statistics}}}}
+
* {{App|IO|Provides input and output in external formats such as XML, CSV or XLS.|http://octave.sourceforge.net/io/index.html|{{AUR|octave-io}}}}
+
* {{App|Signal|Provides functions for processing images|http://octave.sourceforge.net/image/index.html|{{AUR|octave-signal}}}}
+
* {{App|Multicore|Provides functions for parallel processing on multiple cores.|http://octave.sourceforge.net/multicore/index.html|{{AUR|octave-multicore}}}}
+
 
+
A complete list can be found on [http://octave.sourceforge.net/packages.php Octave-Forge].
+
  
=== Packaging ===
+
Octave provides a set of packages, similar to Matlab's Toolboxes, through [http://octave.sourceforge.net/index.html Octave-Forge]. The complete list of packages is [http://octave.sourceforge.net/packages.php here].
  
Creating an Octave-forge package for Arch is easy using the [https://github.com/drizzd/octave-forge-archlinux#readme Octave-forge helper scripts for Archlinux].
+
Packages can be installed directly in Octave, or from the AUR. See below.
  
 
=== Using Octave's installer ===
 
=== Using Octave's installer ===
  
Packages can also be managed using Octave's installer. To install a package:
+
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:
  
# Download the {{ic|.tar.gz}} package from Octave-Forge.
+
octave:1> pkg install -forge packagename
# Install it from Octave as user by executing:
+
  
octave:1> pkg install packagename.tar.gz
+
{{Note|Some Octave's packages, like {{ic|control}}, need the {{Pkg|gcc-fortran}} ArchLinux's package in order to compile and install.}}
 
+
Packages have dependencies which you have to install before installing your package, if you want to bypass this use:
+
 
+
octave:2> pkg install -no-deps packagename.tar.gz
+
  
 
To uninstall a package:
 
To uninstall a package:
 
   
 
   
  octave:3> pkg uninstall packagename.tar.gz
+
  octave:3> pkg uninstall packagename
  
 
Some packages get loaded automatically by Octave, for those which do not:
 
Some packages get loaded automatically by Octave, for those which do not:
Line 55: Line 43:
  
 
To see which packages have been loaded use {{ic|pkg list}}, the packages with an asterisk are the ones that are already loaded.
 
To see which packages have been loaded use {{ic|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:
 +
 +
{{hc|/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 ([https://aur.archlinux.org/packages.php?O=0&K=octave-&do_Search=Go search packages]). New Octave-forge packages for Arch can be created semi-automatically using the [https://github.com/drizzd/octave-forge-archlinux#readme Octave-forge helper scripts for Archlinux].
  
 
== Plotting ==
 
== Plotting ==
Line 61: Line 63:
 
* {{App|[[Wikipedia:Gnuplot|Gnuplot]]|A classic Linux plotting utility.|http://www.gnuplot.info/|{{Pkg|gnuplot}}}}
 
* {{App|[[Wikipedia:Gnuplot|Gnuplot]]|A classic Linux plotting utility.|http://www.gnuplot.info/|{{Pkg|gnuplot}}}}
 
* {{App|FLTK Backend|A new experimental OpenGL backend based on the [[Wikipedia:FLTK|FLTK]] GUI toolkit.|http://www.gnu.org/software/octave/|{{Pkg|octave}}}}
 
* {{App|FLTK Backend|A new experimental OpenGL backend based on the [[Wikipedia:FLTK|FLTK]] GUI toolkit.|http://www.gnu.org/software/octave/|{{Pkg|octave}}}}
{{Note|To enable the FLTK backend, you need to install the {{Pkg|fltk}} package.}}
+
{{Note|To enable the FLTK backend, you need to install the {{Pkg|fltk}} package.  This package now comes as a dependency of octave.}}
  
GnuPlot is still the default, but it can be changed by:
+
FLTK is now the default plotting utility, but due to some serious problems with the experimental interface, you may want to re-enable gnuplot.
  
  octave:1> graphics_toolkit("fltk");
+
  octave:1> graphics_toolkit("gnuplot");
  
 
To make this change permanent add it to your {{ic|~/.octaverc}} file.
 
To make this change permanent add it to your {{ic|~/.octaverc}} file.
  
 
== Graphical interfaces ==
 
== Graphical interfaces ==
 +
Since Octave 3.8, Octave has its own (experimental) GUI based on Qt. Since the 4.0.0 release, it is enabled by default. To start the GUI, just run {{ic|octave}}.
  
There are very few graphical interfaces for Octave and none of them are official:
+
The following GUIs are unofficial.
* {{App|Cantor|A graphical user interface that delegates its mathematical operations to one of several back ends (Scilab, Maxima, Octave and others).|http://edu.kde.org/cantor/|{{Pkg|kdeedu-cantor}}}}
+
* {{App|Cantor|A graphical user interface that delegates its mathematical operations to one of several back ends (Scilab, Maxima, Octave and others).|http://edu.kde.org/cantor/|{{Pkg|cantor}}}}
 
* {{App|QtOctave|A Qt frontend for Octave.|https://forja.rediris.es/projects/csl-qtoctave/|{{AUR|qtoctave}}}}
 
* {{App|QtOctave|A Qt frontend for Octave.|https://forja.rediris.es/projects/csl-qtoctave/|{{AUR|qtoctave}}}}
 +
 +
=== Bug in Documentation tab ===
 +
 +
As of Octave version 3.8.1, clinking a link in the Documentation tab of the official GUI causes the GUI to freeze. According to [https://savannah.gnu.org/bugs/?38305 bug report #38305], this is caused by a signal handler conflict between Octave and Qt.
 +
 +
One [https://lists.gnu.org/archive/html/help-octave/2014-03/msg00049.html workaround] is to unzip the Octave Info files located at {{ic|/usr/share/info/octave.info*}} with the command:
 +
# gunzip /usr/share/info/octave.info*
 +
 +
Another option is to ignore the Documentation tab and use a different Info reader.
  
 
== Reading Microsoft Excel Spreadsheets ==
 
== Reading Microsoft Excel Spreadsheets ==
Line 81: Line 93:
 
==== Converting to an open format ====
 
==== Converting to an open format ====
  
The easiest way to use {{ic|.xls}} files in Octave would be to convert them to {{ic|.csv}} or {{ic|.ods}} using Calc (limited to 1024 columns) from [[Libreoffice]] or [http://www.calligra.org/sheets/ Sheets](limited to 32768 columns) from the the [http://www.calligra-suite.org/ Calligra Suite].
+
The easiest way to use {{ic|.xls}} files in Octave would be to convert them to {{ic|.csv}} or {{ic|.ods}} using Calc (limited to 1024 columns) from [[LibreOffice]] or [http://www.calligra.org/sheets/ Sheets](limited to 32768 columns) from the the [http://www.calligra-suite.org/ Calligra Suite].
  
 
After the conversion is complete you can use the build-in Octave function {{ic|csvread}} for {{ic|.csv}} files:
 
After the conversion is complete you can use the build-in Octave function {{ic|csvread}} for {{ic|.csv}} files:
Line 91: Line 103:
 
  octave:1> odsread('myfile.ods');
 
  octave:1> odsread('myfile.ods');
  
For {{ic|.xlsx}} files you can use the {{AUR|xlsx2csv}} package from [[AUR]]:
+
For {{ic|.xlsx}} files you can use the {{AUR|xlsx2csv}}{{Broken package link|{{aur-mirror|xlsx2csv}}}} package from [[AUR]]:
  
 
   xlsx2csv -t /path/to/save/location -x /path/to/myfile.xlsx  
 
   xlsx2csv -t /path/to/save/location -x /path/to/myfile.xlsx  
Line 99: Line 111:
 
If you must work with XLS files and you cannot convert them to CSV or ODS, for whatever reason, you can use the {{ic|xlsread}} function from the {{AUR|octave-io}} package.
 
If you must work with XLS files and you cannot convert them to CSV or ODS, for whatever reason, you can use the {{ic|xlsread}} function from the {{AUR|octave-io}} package.
  
{{ic|xlsread}} is Java-based and as such requires some [[Java]] libraries to enable support for XLS files.
+
Since {{AUR|octave-io}} version 1.2.5., an interface called 'OCT' was added, which perform reading .xlsx (not .xls!), ods and .gnumeric without any dependencies. However, the Java-based interface still exist (special for reading .xls files and writing those file formats).
  
 +
===== Steps necessary to make Java Interface available =====
 +
{{Out of date|The package octave-java is now included in octave, and no longer available from AUR.}}
 
The steps necessary to make it work are:
 
The steps necessary to make it work are:
:1. [[Pacman|Install]] {{Pkg|jdk7-openjdk}}, available in the [[official repositories]].
+
:1. [[Install]] {{Pkg|jdk7-openjdk}}, available in the [[official repositories]].
  
 
{{Note|A common problem is that Octave cannot find the JDK path. To fix this execute the following commands in your shell:
 
{{Note|A common problem is that Octave cannot find the JDK path. To fix this execute the following commands in your shell:
Line 109: Line 123:
  
 
:2. Install a Java XLS library for {{ic|xlsread}}. There are more such libraries available, a comparison can be found at [http://octave.org/wiki/index.php?title=IO_package#Comparison_of_interfaces_.26_usage here]. The recommended library is {{AUR|apache-poi}}, available in the [[AUR]].
 
:2. Install a Java XLS library for {{ic|xlsread}}. There are more such libraries available, a comparison can be found at [http://octave.org/wiki/index.php?title=IO_package#Comparison_of_interfaces_.26_usage here]. The recommended library is {{AUR|apache-poi}}, available in the [[AUR]].
 
:3. Finally, install the {{AUR|octave-java}} package from [[AUR]].
 
  
 
To check if Java is working correctly in Octave, see the output of:
 
To check if Java is working correctly in Octave, see the output of:
Line 142: Line 154:
  
 
To make this permanent add the {{ic|javaaddpath}} commands to your {{ic|~/.octaverc}} file.
 
To make this permanent add the {{ic|javaaddpath}} commands to your {{ic|~/.octaverc}} file.
 +
 +
== Troubleshooting ==
 +
 +
=== Zsh Undecodable Token ===
 +
If you get error
 +
undecodable token: b(hex)[23m
 +
when printing, install {{Pkg|grml-zsh-config}}  and relogin.

Latest revision as of 10:08, 20 February 2016

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

Octave can be installed with the package octave, available in the official repositories.

Note: By default the octave command provided by this package attempts to run the gui and fails if you haven't installed qscintilla[broken link: package not found], which is needed for the gui. To start the command line interface run the octave-cli command instead.

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 directly in Octave, or from the AUR. See below.

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
Note: Some Octave's packages, like control, need the gcc-fortran ArchLinux'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

or

octave:5> pkg load all

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 Archlinux.

Plotting

Octave has two official plotting backends:

  • Gnuplot — A classic Linux plotting utility.
http://www.gnuplot.info/ || gnuplot
  • FLTK Backend — A new experimental OpenGL backend based on the FLTK GUI toolkit.
http://www.gnu.org/software/octave/ || octave
Note: To enable the FLTK backend, you need to install the fltk package. This package now comes as a dependency of octave.

FLTK is now the default plotting utility, but due to some serious problems with the experimental interface, you may want to re-enable gnuplot.

octave:1> graphics_toolkit("gnuplot");

To make this change permanent add it to your ~/.octaverc file.

Graphical interfaces

Since Octave 3.8, Octave has its own (experimental) GUI based on Qt. Since the 4.0.0 release, it is enabled by default. To start the GUI, just run octave.

The following GUIs are unofficial.

  • Cantor — A graphical user interface that delegates its mathematical operations to one of several back ends (Scilab, Maxima, Octave and others).
http://edu.kde.org/cantor/ || cantor
  • QtOctave — A Qt frontend for Octave.
https://forja.rediris.es/projects/csl-qtoctave/ || qtoctaveAUR

Bug in Documentation tab

As of Octave version 3.8.1, clinking a link in the Documentation tab of the official GUI causes the GUI to freeze. According to bug report #38305, this is caused by a signal handler conflict between Octave and Qt.

One workaround is to unzip the Octave Info files located at /usr/share/info/octave.info* with the command:

# gunzip /usr/share/info/octave.info*

Another option is to ignore the Documentation tab and use a different Info reader.

Reading Microsoft Excel Spreadsheets

There are several ways to read Microsoft Excel files with Octave.

Converting to an open format

The easiest way to use .xls files in Octave would be to convert them to .csv or .ods using Calc (limited to 1024 columns) from LibreOffice or Sheets(limited to 32768 columns) from the the Calligra Suite.

After the conversion is complete you can use the build-in Octave function csvread for .csv files:

octave:1> csvread('myfile.csv');

For .ods files the octave-ioAUR package is necessary which contains the odsread function:

octave:1> odsread('myfile.ods');

For .xlsx files you can use the xlsx2csvAUR[broken link: archived in aur-mirror] package from AUR:

 xlsx2csv -t /path/to/save/location -x /path/to/myfile.xlsx 

Reading xls files directly from Octave

If you must work with XLS files and you cannot convert them to CSV or ODS, for whatever reason, you can use the xlsread function from the octave-ioAUR package.

Since octave-ioAUR version 1.2.5., an interface called 'OCT' was added, which perform reading .xlsx (not .xls!), ods and .gnumeric without any dependencies. However, the Java-based interface still exist (special for reading .xls files and writing those file formats).

Steps necessary to make Java Interface available

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: The package octave-java is now included in octave, and no longer available from AUR. (Discuss in Talk:Octave#)

The steps necessary to make it work are:

1. Install jdk7-openjdk, available in the official repositories.
Note: A common problem is that Octave cannot find the JDK path. To fix this execute the following commands in your shell:
$ export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
You may also want to add this to your ~/.bashrc and append it to your PATH.
2. Install a Java XLS library for xlsread. There are more such libraries available, a comparison can be found at here. The recommended library is apache-poiAUR, available in the AUR.

To check if Java is working correctly in Octave, see the output of:

 octave:1> javaclasspath 
  STATIC JAVA PATH
     - empty -
  DYNAMIC JAVA PATH
     - empty -

To load the selected library in Octave, check if it is in the Java path. If not:

 octave:1> javaaddpath path/to/file.jar

In the case you chose apache-poiAUR, the relevant JAR files can be found in /usr/share/java/apache-poi/poi-3.x.jar and /usr/share/java/apache-poi/poi-ooxml-3.x.jar.

To check if it works

 octave:1> chk_spreadsheet_support 

The output should be > 0:

                   0 No spreadsheet I/O support found
                 ---------- XLS (Excel) interfaces: ----------
                   1 = COM (ActiveX / Excel)
                   2 = POI (Java / Apache POI)
                   4 = POI+OOXML (Java / Apache POI)
                   8 = JXL (Java / JExcelAPI)
                  16 = OXS (Java / OpenXLS)
                 --- ODS (OpenOffice.org Calc) interfaces ----
                  32 = OTK (Java/ ODF Toolkit)
                  64 = JOD (Java / jOpenDocument)
                 ----------------- XLS & ODS: ----------------
                 128 = UNO (Java / UNO bridge - OpenOffice.org)

To make this permanent add the javaaddpath commands to your ~/.octaverc file.

Troubleshooting

Zsh Undecodable Token

If you get error

undecodable token: b(hex)[23m

when printing, install grml-zsh-config and relogin.