FAQ: Difference between revisions

Jump to navigation Jump to search
4,495 bytes added ,  17 December 2016
Update some outdated links.
(→‎GUI: update to note that GUI has been released)
(Update some outdated links.)
(39 intermediate revisions by 17 users not shown)
Line 1: Line 1:
This is a list of frequently asked questions (FAQ) for GNU Octave users.
This is a list of frequently asked questions (FAQ) for GNU Octave users.


We are always looking for new questions (with answers), better answers, or both. Feel free to edit this page with your changes. If you have general questions about GNU Octave, or need help for something that is not covered by the Octave manual or the FAQ, please use the [https://mailman.cae.wisc.edu/listinfo/help-octave help@octave.org mailing list].
We are always looking for new questions (with answers), better answers, or both. Feel free to edit this page with your changes. If you have general questions about GNU Octave, or need help for something that is not covered by the Octave manual or the FAQ, please use the [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org mailing list].


This FAQ is intended to supplement, not replace, the GNU Octave manual. Before posting a question to the [https://mailman.cae.wisc.edu/listinfo/help-octave help@octave.org mailing list], you should first check to see if the topic is covered in the manual.
This FAQ is intended to supplement, not replace, the GNU Octave manual ([https://www.gnu.org/software/octave/doc/interpreter/ HTML], [https://www.gnu.org/software/octave/octave.pdf PDF]). Before posting a question to the [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org mailing list], you should first check to see if the topic is covered in the manual.
 
<div class="tocinline">__TOC__</div>


=General=
=General=
Line 18: Line 20:


==What is Octave-Forge?==
==What is Octave-Forge?==
[http://octave.sourceforge.net/ Octave-Forge] is a collection of packages for GNU Octave, something similar to the Matlab toolboxes. When talking about the two projects at the same time, GNU Octave is usually referred to as Octave core (or just ''core''). [http://octave.sourceforge.net/ Octave-Forge] also serves as a test bed for code that may eventually end up in the core, and distributes binaries for systems with a lack of developers tools (mainly Windows).
 
[https://octave.sourceforge.io/ Octave-Forge] is a collection of packages for GNU Octave, something similar to the Matlab toolboxes. When talking about the two projects at the same time, GNU Octave is usually referred to as Octave core (or just ''core''). [https://octave.sourceforge.io/ Octave-Forge] also serves as a test bed for code that may eventually end up in the core, and distributes binaries for systems with a lack of developers tools (mainly Windows).


==Who uses Octave?==
==Who uses Octave?==
Line 60: Line 63:
Octave is also free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 3, as published by the Free Software Foundation, or at your option any later version.
Octave is also free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 3, as published by the Free Software Foundation, or at your option any later version.


==Why are the developers planning to replace Gnuplot with an OpenGL backend?==
== How can I cite Octave? ==


The development of Octave is committed to being both compatible with Matlab and adding additional features. Toward those ends, the development community has chosen to introduce a native OpenGL backend that supports Matlab handle graphics and its uicontrols. Starting with the 3.8 release, Octave now uses OpenGL graphics by default with FLTK widgets. A Qt OpenGL toolkit is also [https://github.com/goffioul/QtHandles under development].
Octave is free software and does not legally bind you to cite it. However,
we have invested a lot of time and effort in creating GNU Octave, and we
would appreciate if you would cite if you used.


There are no plans to remove the gnuplot backend. While a better backend may some day become the new default plotter, the gnuplot backend will still be available as long as our users find it useful.
Run {{codeline|citation}} at the Octave prompt for details on how to best
cite the Octave version you are running. Certain Octave packages also have
recommended citations in which case use {{codeline|citation package_name}}.


==How can I cite Octave?==
Ideally, you should cite the software itself, not a book or manual, like so:


Pointing to http://www.octave.org is good, because that gives people a direct way to find out more. If citation of a URL is allowed by the publisher you can use this entry (update year and version accordingly!):
  @software{octave,
    author = {John W. Eaton and others},
    title = {GNU Octave},
    url = {http://www.octave.org},
    version = {4.0.0},
    date = {2015-05-27},
  }


    <nowiki>@MISC{octave:2014,
It is recommended to do so on a first draft submitted.  However, some editors
    author = {{Octave community}},
may disallow this, in which case you can still make a general reference
    keywords = {Octave,Software},
to Octave in the text, such as:
    title = {{GNU Octave 3.8.1}},
    url = {www.gnu.org/software/octave/},
    year = {2014}
    }</nowiki>


if you also want to point to a traditional reference, then you can cite the Octave manual:
<blockquote>
This work made use of the free software package GNU Octave, and the authors are grateful for the support of the Octave development community.
</blockquote>
 
If a more traditional reference is required, there is also a manual for each
Octave release that can be cited:


    <nowiki>@BOOK{eaton:2009,
  @book{,
     author    = {John W. Eaton and David Bateman and S\oren Hauberg},
     author    = {John W. Eaton, David Bateman, S\oren Hauberg, and Rik Wehbring},
     title    = {{GNU Octave} version 3.0.1 manual: a high-level interactive language for numerical computations},
     title    = {{GNU Octave} version 4.0.0 manual: a high-level interactive language for numerical computations},
    publisher = {CreateSpace Independent Publishing Platform},
     year      = {2015},
     year      = {2009},
    note      = {{ISBN} 1441413006},
     url      = {http://www.gnu.org/software/octave/doc/interpreter},
     url      = {http://www.gnu.org/software/octave/doc/interpreter},
    }</nowiki>
  }


Note that there are two reasons for citing the software used.  One is giving
recognition to the work done by others which we already addressed. The other
is giving details on the system used so that experiments can be replicated.
This is just as important, if not more.


If you want to acknowledge Octave instead of citing it, you can use text such as this:
For this, you should cite the version of Octave and all packages used, as
 
well as any details of your setup as part of your Methods.  In addition,
<blockquote>
you should make your source available.  See
The data has been numerically analyzed with the free software package GNU Octave.
[http://software.ac.uk/so-exactly-what-software-did-you-use How to cite and describe software]
</blockquote>
for more details and an in depth discussion.
 
or
 
<blockquote>
This work made use of the free software package GNU Octave, and the authors are grateful for the support of the Octave development community.
</blockquote>


==When will feature X be released or implemented?==
==When will feature X be released or implemented?==
Line 107: Line 117:
==How can I get involved in Octave development?==
==How can I get involved in Octave development?==


Be around. Be social. Participate in the [https://mailman.cae.wisc.edu/listinfo/help-octave help] and [https://mailman.cae.wisc.edu/listinfo/octave-maintainers maintainers] mailing lists. Find things about Octave you don't like, and start thinking about how to fix them. Many people who now contribute to Octave first spent several years helping in the mailing list before they started to delve into the code. A good way to learn Octave is to understand the problems other people are having with it, so being helpful in the mailing lists not only helps Octave as a whole, but it also prepares you to be a better Octave contributor.
Be around. Be social. Participate in the [https://mailman.cae.wisc.edu/listinfo/help-octave help]
and [https://mailman.cae.wisc.edu/listinfo/octave-maintainers maintainers]
mailing lists. Find things about Octave you don't like, and start thinking
about how to fix them. Many people who now contribute to Octave first spent
several years helping in the mailing list before they started to delve into
the code. A good way to learn Octave is to understand the problems other
people are having with it, so being helpful in the mailing lists not only
helps Octave as a whole, but it also prepares you to be a better Octave
contributor.


If you feel ready to dive right into the code, read [[Hacking | here]] and [http://www.gnu.org/software/octave/get-involved.html here] for guidance. One of the best ways for understanding how Octave works is to [[Debugging Octave|run it in a debugger]].
If you feel ready to dive right into the code, read [[Hacking | here]]
and [http://www.gnu.org/software/octave/get-involved.html here] for
guidance. But do not send an email to the mailing lists listing your
skills and offering to help.  We won't just suggest things for you to do.
We lack volunteers and we do need your help, but because of that, we also
lack the time to provide good guidance and mentoring.  If there is a
specific short-term project you would like to work on, say so, and just
do it.  Then ask for help or advice when you're doing it.  It is a lot
more important that you do something that you're actually interested on
than something we suggested because it only matches your skills.


We also need help with this wiki and the [http://www.gnu.org/software/octave/doc/interpreter/ manual]. These are also important tasks. The documentation is easier to patch, so you can discuss improvements to it and submit patches. Or just edit this wiki!
We also need help with this wiki and the
[http://www.gnu.org/software/octave/doc/interpreter/ manual]. These are
also important tasks. The documentation is easy to patch, and the help text
for individual functions even more so. Editing this wiki is even easier.


Accurate bug reporting is also very useful. Find and report [http://www.gnu.org/software/octave/bugs.html bugs], making an attempt to diagnose them. Eventually, you will also know how to fix them. If you want to help with bug reports or patches, subscribe to [https://savannah.gnu.org/mail/?group=octave the bug tracker mailing list]. You'll get updates on all bug activity, and you can jump in when you see something you can help with.
Accurate bug reporting is also very useful. Find and report
[http://www.gnu.org/software/octave/bugs.html bugs], making an attempt to
diagnose them. Eventually, you will also know how to fix them. If you want
to help with bug reports or patches, subscribe to
[https://savannah.gnu.org/mail/?group=octave the bug tracker mailing list].
You'll get updates on all bug activity, and you can jump in when you see
something you can help with.


Look at our [[Projects]] and [[Summer of Code Project Ideas]] if you need specific inspiration for coding tasks that we would like to get done. See also the list of [[short projects]].
Look at our [[Projects]] and [[Summer of Code Project Ideas]] if you need
specific inspiration for coding tasks that we would like to get done. See
also the list of [[short projects]].


=Licensing issues=
=Licensing issues=
Line 155: Line 193:


=What's new in Octave=
=What's new in Octave=
==What's new in version series 3.6.N and 3.7.N of Octave==


Several new features have been added to the 3.6.N series. The full details are in [https://www.gnu.org/software/octave/NEWS-3.6.html the NEWS file], but in brief 3.6.N series brings:
Each new Octave release introduces many new features.  The following are
a distilled list of the major changes.  A complete list of user visible
changes can be seen by running {{codeline|news}} at the Octave prompt, and
a full list of changes is on the {{Filepath|Changelog}} distributed with
the Octave sources.
 
==Coming in a future release==
See [http://hg.savannah.gnu.org/hgweb/octave/file/tip/NEWS NEWS on the development branch]
 
==What's new in version series 4.0.X of Octave==
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-4.0.html NEWS file].
 
* First official release of the GUI.
* Release of official windows binaries.
* Experimental support for [[classdef]].
* OpenGL graphics with Qt widgets.
* Several functions for reading, writing, and recording of audio.
 
==What's new in version series 3.8.X of Octave==
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.8.html NEWS file].
 
* Experimental GUI interface.
* OpenGL graphics with fltk widgets.
* Support for nested functions.
* Support for java packages in Octave core.
* Reading and writing of image files vastly extended.
 
==What's new in version series 3.6.X of Octave==
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.6.html NEWS file].


* Perl compatible regular expressions
* Perl compatible regular expressions
* A profiler has been added.
* A profiler has been added.
* Broadcasting enabled for all built-in binary element-wise operators.
* Broadcasting enabled for all built-in binary element-wise operators.
* The statistical distribution functions have been overhauled.
* The functions strread(), textscan(), and textread() have been rewritten.
* Performance of all m-file string functions has been improved.
* Performance of all m-file string functions has been improved.
* The qhull geometry functions have been revamped.
* Date/time functions have been updated.
* Matlab compatible preference functions have been added.
* Various handle graphics functions have been introduced.
* The parfor keyword is now recognized.


==Features added in version series 3.4.N and 3.5.N of Octave==
==What's new in version series 3.4.X of Octave==
Here are some features that have been around since 3.4.N
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.4.html NEWS file].


* Many improvements to native OpenGL plotting
* Many improvements to native OpenGL plotting
* ARPACK now distributed with Octave
* ARPACK now distributed with Octave
* Indexing optimisations
* Indexing optimisations
* FTP object using libcurl
* FTP objects
* Better consistency with ismatrix, issquare, and issymetric
* Function handles aware of overloaded functions
* Function handles aware of overloaded functions
* More efficient matrix division by making a single LAPACK call
* Other optimisations in matrix operations
* bsxfun optimised for basic arithmetic functions
* bsxfun optimised for basic arithmetic functions
* Matlab-style ignoring of output arguments using {{Codeline|~}}
* Matlab-style ignoring of output arguments using {{Codeline|~}}
* Many optimisations of the accumarray function
* Many optimisations of the accumarray function
* Sparse matrix indexing has been rewritten for speed
* Sparse matrix indexing has been rewritten for speed
* Configuration pseudo-variables like page_screen_output accept a  "local" option argument to limit their scope to function scope
* The pkg command now accepts a -forge option to pull packages directly from Octave-forge
* The pkg command now accepts a -forge option to pull packages directly from Octave-forge
* Several dlmread improvements
* Octave now uses gnulib for better cross-platform compatibility


==Features added in version series 3.2.N and 3.3.N of Octave==
==What's new in version series 3.2.X of Octave==
Here are some features that have been around since 3.2.N
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.2.html NEWS file].


* integer types
* Single precision type
* fixed point arithmetic
* Experimental OpenGL graphics toolkit to replace gnuplot
* sparse matrices
* Object orient programming via @class named directories
* linear programming code based on GLPK
* 64-bit compilation support
* 64-bit compilation support
* gzipped files and stream and consequently support of Matlab v7 files
* gzipped files and stream and consequently support of Matlab v7 files
* better support for both msvc and mingw
* a fully compatible MEX interface
* a fully compatible MEX interface
* many many other minor features and compatibility changes
* an experimental OpenGL graphics toolkit to replace gnuplot
* object orient programming
* block comments
* imwrite and imread (based on the GraphicsMagick library)
* imwrite and imread (based on the GraphicsMagick library)
* Lazy transpose <br/> Special treatment in the parser of things like "a' * b", where the transpose is never explicitly formed but a flag is rather passed to the underlying LAPACK code.
* Lazy transpose <br/> Special treatment in the parser of things like "a' * b", where the transpose is never explicitly formed but a flag is rather passed to the underlying LAPACK code.
* Single precision type
* Improved array indexing <br/> The underlying code used for indexing of arrays has been completely rewritten and so the indexing of arrays is now significantly faster.


==Features available since 2.1.N==
== Older releases ==
Here are some older features that have been around since 2.1.N:


* NDArrays
For full details on older releases, see:
* cells


==Coming in a future release==
* [http://hg.savannah.gnu.org/hgweb/octave/file/83792dd9bcc1/etc/NEWS.1 NEWS.1] for the 1.X.Y series
See [http://hg.savannah.gnu.org/hgweb/octave/file/tip/NEWS NEWS on the development branch]
* [http://hg.savannah.gnu.org/hgweb/octave/file/83792dd9bcc1/etc/NEWS.2 NEWS.2] for the 2.X.Y series
* [http://hg.savannah.gnu.org/hgweb/octave/file/83792dd9bcc1/etc/NEWS.3 NEWS.3] for the 3.X.Y series


=What documentation exists for Octave?=
=What documentation exists for Octave?=
Line 261: Line 309:


* http://www.octave.org/download.html
* http://www.octave.org/download.html
* ftp://ftp.octave.org/pub/octave/
* https://ftp.gnu.org/gnu/octave/


Since Octave is distributed under the terms of the GPL, you can get Octave from a friend who has a copy, or from the Octave website.
Since Octave is distributed under the terms of the GPL, you can get Octave from a friend who has a copy, or from the Octave website.


==Pre-compiled binary packages==
==Pre-compiled binaries ==
:''See also: [[Build from source]]''


The Octave project does not distribute binary packages, but other projects do. For an up-to-date listing of packagers, see:
The Octave project does not normally distribute its own binaries, but other projects do.  
For example, Linux and BSD distributions provide by their respective Octave binaries.
Windows is a recent exception, in that binaries are available directly from the Octave project (starting from version 4.0).
For an up-to-date listing, see:


* http://www.octave.org/download.html
* http://www.octave.org/download.html
* [[Build From Source]]


As of today, Octave binaries are available at least on Debian, Ubuntu, RedHat, Suse and Fedora GNU/Linux, Mac OS X, Windows versions 98, 2000, XP, Vista, 7 and 8.
As of today, Octave binaries are available at least on Debian, Ubuntu, RedHat, Suse, and Fedora GNU/Linux; Mac OS X; and Windows (versions 98, 2000, XP, Vista, 7, 8, and 10).


==How do I get a copy of Octave for (some other platform)?==
==How do I get a copy of Octave for (some other platform)?==
Line 281: Line 332:


There is an unofficial Octave app available for Android in the Google Play store. Please see [[Android]] for more information.
There is an unofficial Octave app available for Android in the Google Play store. Please see [[Android]] for more information.
This version of Octave is no longer freely available and has become 'nagware'. This is a sad turn of events.


=Installation issues and problems=  
=Installation issues and problems=  
Line 298: Line 351:
Yes, but development is done primarily with GCC, so you may hit some incompatibilities. Octave is intended to be portable to any standard conforming compiler. If you have difficulties that you think are bugs, please report them to the http://bugs.octave.org bug tracker, or ask for help on the [mailto:help@octave.org mailing list].
Yes, but development is done primarily with GCC, so you may hit some incompatibilities. Octave is intended to be portable to any standard conforming compiler. If you have difficulties that you think are bugs, please report them to the http://bugs.octave.org bug tracker, or ask for help on the [mailto:help@octave.org mailing list].


== How do I install ''all'' Octave packages? ==
== How do install or load all Octave packages? ==
Do not do it! Really, there is no reason to do this. Octave Forge has many packages for different needs but it's unlikely that you need all of them. The common misconception is that the more packages one installs, the more complete and powerful its octave installation will be. However, in the same way one would ''never'' install all perl modules, ruby gems or python packages (because it simply makes no sense), one should not install all octave packages. This isn't desirable and it's not even possible.


Packages should be installed and loaded selectively. Note that some packages are meant to shadow core functions changing the way Octave works, and different packages can have different implementations of a function with the same name, leading to unpredictable results. Others are just broken or crappy and will break your system. What's worse, some of them packages are even loaded automatically at startup so you may be screwing your octave installation without even realizing it.
Do not do it!  Really, there is no reason to do this.  Octave has many
packages for different needs and is unlikely that you need all of
them.  You either have a small set of required packages, in which case
you know them by name; or you want them all "just because", in which case
you don't really need them.
 
The common misconception is that the more packages one has installed
and loaded, the more complete and powerful its Octave installation will be.
However, in the same way one would never install all perl modules,
ruby gems, python packages, and C++ libraries (because it simply makes
no sense), one should not install all Octave packages.
 
Packages should be installed and loaded selectively. Note that some
packages are meant to shadow core functions changing the way Octave works,
and that different packages can have different functions with the same name
leading to unpredictable results.
 
If you really really really want to do load all packages, you can with
the following:
 
## WARNING: loading all packages is probably not the solution you are looking for.
cellfun (@(x) pkg ("load", x.name), pkg ("list"));
 
 
== How do I automatically load a package at Octave startup? ==
 
When Octave starts, it runs {{Path|~/.octaverc}}.  If you want Octave to
automatically load a package, simply add a {{codeline|pkg load pkg-name}}
command to it.  If the files does not exist, create it.
 
If you do this, remember that other people may not have Octave configured
to load packages at startup.  Therefore, if you write code for others,
remember that your programs still need to load the packages they require.


=Coding=
=Coding=
Line 322: Line 406:


As a natural extension of this, functions can also be defined in script files (m-files whose first non-comment line isn't {{Codeline|function out &#61; foo (...)}})
As a natural extension of this, functions can also be defined in script files (m-files whose first non-comment line isn't {{Codeline|function out &#61; foo (...)}})
Note: MATLAB R2016b added the ability to [http://www.mathworks.com/help/matlab/matlab_prog/local-functions-in-scripts.html define functions in script files].


===Comments with #===
===Comments with #===
Line 400: Line 486:
     x += 1;
     x += 1;
   until (x == 10)
   until (x == 10)
===Broadcasting===
Borrowed from [http://stackoverflow.com/q/26948776/3565696 other languages], [http://www.gnu.org/software/octave/doc/v4.0.1/Broadcasting.html octave broadcasting] allows easy and readable vectorization.
  f = (1:0.1:2);
  # put angular frequencies on the first dimension to prepare broadcasting
  omega = 2 * pi * f(:);
  # time is already on the second dimension (row vector)
  t = 0:0.02:2;
  # the resulting s will be a 2-dimensional array
  s = sin(omega .* t);
  # which can be displayed as
  pcolor(t, f, s)
  xlabel("t (s)")
  ylabel("f (Hz)")
Note: [https://www.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html Automatic expansion of dimensions] was added to MATLAB R2016b.


==How does Octave solve linear systems?==
==How does Octave solve linear systems?==
Line 540: Line 644:
would produce value 9999999999999990000, which is close to the maximum possible value for the uint64 type, but can't be at the moment input directly, doing uint64(9999999999999990000), due to the mentioned error of rounding.
would produce value 9999999999999990000, which is close to the maximum possible value for the uint64 type, but can't be at the moment input directly, doing uint64(9999999999999990000), due to the mentioned error of rounding.


Alternatively, one may use arbitrary precision arithmetic, which has as much precision as is practical to hold in your computer's memory. The ''symbolic'' package, when it works, has a vpa() function for arbitrary precision arithmetic. Note that arbitrary precision arithmetic must be implemented '''in software''' which makes it much slower than hardware floats.
Alternatively, one may use arbitrary precision arithmetic, which has as much precision as is practical to hold in your computer's memory. The ''symbolic'' package has a vpa() function for arbitrary precision arithmetic. Note that arbitrary precision arithmetic must be implemented '''in software''' which makes it much slower than hardware floats.
 
Consider carefully if your problem really needs more precision. Often if you're running out of precision the problem lies fundamentally in your methods being [http://en.wikipedia.org/wiki/Numerical_stability numerically unstable], so more precision will not help you here. If you absolutely must use arbitrary-precision arithmetic, you're at present better off using a CAS instead of Octave. An example of such a CAS is [http://sagemath.org Sage].
 
==How do I run a Matlab P-file in Octave?==


At present, however, the symbolic package is almost useless, since even when you get it to compile and not crash, it cannot handle any array type, which hardly helps for an array-oriented language like Octave. If this limitation is not important to you, attempt to use the symbolic package. If you would like to get this fixed, [http://octave.1599824.n4.nabble.com/Internal-Precision-Symbolic-tp4645257p4645594.html Jordi Gutiérrez Hermoso has volunteered] to fix the package for 5000 USD, which can be obtained from a kickstarter campaign.
You can't. Matlab P-files (files with a .p file extension), also known as P-code, are [https://en.wikipedia.org/wiki/Obfuscation_%28software%29 obfuscated] files than cannot be run outside of Matlab itself. The original source Matlab m-files that were used to generate the P-files should be used in Octave instead.


Consider carefully if your problem really needs more precision. Often if you're running out of precision the problem lies fundamentally in your methods being [http://en.wikipedia.org/wiki/Numerical_stability numerically unstable], so more precision will not help you here. If you absolutely must use arbitrary-precision arithmetic, you're at present better off using a CAS instead of Octave. An example of such a CAS is [http://sagemath.org Sage].
There are no plans to support running P-files produced by Matlab in Octave.


=Common problems=
=Common problems=
Line 561: Line 669:


==How do I get sound input or output in Windows?==  
==How do I get sound input or output in Windows?==  
Sound I/O is badly broken on anything that isn't using Linux's Open Sound System. Nowadays, this usually doesn't even include Linux, since OSS is frequently considered "legacy". All of the audio functions in Octave are badly in need of a rewrite so that they actually work.
Sound input from a sound card and output to a sound card is fully supported in Octave 4.0.0 and newer in all operating systems. Older versions of Octave had very limited audio support that was essentially Linux-specific. If you have problems with the audio I/O functions using Octave 4.0 or a newer version, please report them on the [http://bugs.octave.org bug tracker].


==I cannot install a package. Octave complains about a missing mkoctfile.==
==I cannot install a package. Octave complains about a missing mkoctfile.==
Line 587: Line 695:
Floating point arithmetic is an approximation '''in binary''' to arithmetic on real or complex numbers. Just like you cannot represent 1/3 exactly in decimal arithmetic (0.333333 is only a rough approximation to 1/3), you cannot represent some fractions like <math>1/10</math> exactly in base 2. In binary, the representation to one tenth is <math>0.0\overline{0011}_b</math> where the bar indicates that it repeats infinitely (like how <math>1/6 = 0.1\overline{6}_d</math> in decimal). Because this infinite repetition cannot be represented exactly with a finite number of digits, rounding errors occur for values that appear to be exact in decimal but are in fact approximations in binary, such as for example how 0.3 - 0.2 - 0.1 is not equal to zero.
Floating point arithmetic is an approximation '''in binary''' to arithmetic on real or complex numbers. Just like you cannot represent 1/3 exactly in decimal arithmetic (0.333333 is only a rough approximation to 1/3), you cannot represent some fractions like <math>1/10</math> exactly in base 2. In binary, the representation to one tenth is <math>0.0\overline{0011}_b</math> where the bar indicates that it repeats infinitely (like how <math>1/6 = 0.1\overline{6}_d</math> in decimal). Because this infinite repetition cannot be represented exactly with a finite number of digits, rounding errors occur for values that appear to be exact in decimal but are in fact approximations in binary, such as for example how 0.3 - 0.2 - 0.1 is not equal to zero.


This isn't an Octave bug. It happens with any program that uses [http://en.wikipedia.org/wiki/IEEE_754 IEEE 754 floating point arithmetic]. The reason why Octave and other programs use IEEE 754 floats is that they are ''fast'', because they are implemented in hardware. Unless you are using very exotic hardware, Octave will use your computer's processor for floating point arithmetic.
In addition, some advanced operations are computed by approximation and are not guaranteed to be accurate, see [https://en.wikipedia.org/wiki/Rounding#Table-maker.27s_dilemma Table-maker's dilemma]. Their results are system-dependent.
 
This isn't an Octave bug. It happens with any program that uses [http://en.wikipedia.org/wiki/IEEE_754 IEEE 754 floating point arithmetic]. To be fair, IEEE 754 also specifies decimal floating point arithmetic, which has never seen wide adoption. The reason why Octave and other programs use IEEE 754 binary floats is that they are ''fast'', because they are implemented in hardware or system libraries. Unless you are using very exotic hardware, Octave will use your computer's processor for basic floating point arithmetic.


Like death and taxes, rounding errors are a fact of life. You cannot avoid them. You can only move a rounding error from one part of a computation to another, or you can use more precision and delay the rounding error. One way to delay the rounding error is to use arbitrary precision arithmetic, which is inevitably slower as it has to be implemented in software instead of hardware. You may use the vpa function from the symbolic package for this purpose.
Like death and taxes, rounding errors are a fact of life. You cannot avoid them. You can only move a rounding error from one part of a computation to another, or you can use more precision and delay the rounding error. One way to delay the rounding error is to use arbitrary precision arithmetic, which is inevitably slower as it has to be implemented in software instead of hardware. You may use the vpa function from the symbolic package for this purpose.
Line 597: Line 707:
== I have installed a package but still get a "foo undefined" error ==
== I have installed a package but still get a "foo undefined" error ==


You have probably forgotten to load the package. Use {{Codeline|pkg load package-name}} to load it. Most packages are no longer loaded automatically to avoid surprises. See reasoning on related FAQ [[FAQ#How_do_I_install_all_Octave_packages.3F|how do I install all Octave packages]]. If you want a specific package to be loaded by default at startup, consider adding the {{Codeline|pkg load}} command on your {{path|.octaverc}} file.
You have probably forgotten to load the package. Use {{Codeline|pkg load package-name}} to load it. Most packages are no longer loaded automatically to avoid surprises. See reasoning on related FAQ [[FAQ#How_do_I_install_all_Octave_packages.3F|how do I install all Octave packages]]. If you want a specific package to be loaded by default at startup, consider adding the {{Codeline|pkg load}} command on your {{path|[[.octaverc]]}} file.


== Missing lines when printing under Windows with OpenGL toolkit and Intel integrated GPU ==
== Missing lines when printing under Windows with OpenGL toolkit and Intel integrated GPU ==
Line 607: Line 717:
See also https://www.opengl.org/wiki/FAQ#Why_is_my_GL_version_only_1.4_or_lower.3F
See also https://www.opengl.org/wiki/FAQ#Why_is_my_GL_version_only_1.4_or_lower.3F


=Porting programs from Matlab to Octave=
== Plot hangs and makes the GUI unresponsive ==
 
If the Qt graphics toolkit is used and "plot" is used for the first time, the fontconfig scanner searches the font directory to build a font cache. This can take up to 3min on slow CPUs. See {{bug|45458}}
 
= Differences between Octave and Matlab =


People often ask
People often ask
Line 629: Line 743:
You should also look at the pages http://octave.sourceforge.net/packages.php and http://octave.sourceforge.net/docs.html that have a function reference that is up to date. You can use this function reference to see the number of octave functions that are available and their Matlab compatibility.
You should also look at the pages http://octave.sourceforge.net/packages.php and http://octave.sourceforge.net/docs.html that have a function reference that is up to date. You can use this function reference to see the number of octave functions that are available and their Matlab compatibility.


==How is Octave different from Matlab?==
== Nested Functions ==
 
The major differences between Octave 3.4.N and Matlab R2010b are:
 
===Nested Functions===
Octave has limited support for nested functions. That is
Octave has limited support for nested functions. That is


Line 656: Line 766:
The authors of Octave consider the nested function scoping rules of Matlab to be more problems than they are worth as they introduce difficult to find bugs as inadvertently modifying a variable in a nested function that is also used in the parent is particularly easy for those not attentive to detail.
The authors of Octave consider the nested function scoping rules of Matlab to be more problems than they are worth as they introduce difficult to find bugs as inadvertently modifying a variable in a nested function that is also used in the parent is particularly easy for those not attentive to detail.


===Differences in core syntax===
== Differences in core syntax ==


There are a few core Matlab syntaxes that are not accepted by Octave, these being
There are a few core Matlab syntaxes that are not accepted by Octave, these being
Line 666: Line 776:
* Matlab classdef object oriented programming is not yet supported, though work is underway in a branch of the development tree.
* Matlab classdef object oriented programming is not yet supported, though work is underway in a branch of the development tree.


===Differences in core functions===
== Differences in core functions ==


A large number of the Matlab core functions (ie those that are in the core and not a toolbox) are implemented, and certainly all of the commonly used ones. There are a few functions that aren't implemented, usually to do with specific missing Octave functionality (GUI, DLL, Java, ActiveX, DDE, web, and serial functions). Some of the core functions have limitations that aren't in the Matlab version. For example the sprandn function can not force a particular condition number for the matrix like Matlab can.
A large number of the Matlab core functions (ie those that are in the core and not a toolbox) are implemented, and certainly all of the commonly used ones. There are a few functions that aren't implemented, usually to do with specific missing Octave functionality (GUI, DLL, Java, ActiveX, DDE, web, and serial functions). Some of the core functions have limitations that aren't in the Matlab version. For example the sprandn function can not force a particular condition number for the matrix like Matlab can. Another example is that testing and the runtests function work differently in Matlab and Octave.


===Just-In-Time compiler===
== Just-In-Time compiler ==


Matlab includes a "Just-In-Time" compiler. This compiler allows the acceleration of for-loops in Matlab to almost native performance with certain restrictions. The JIT must know the return type of all functions called in the loops and so you can't include user functions in the loop of JIT optimized loops. Octave doesn't have a JIT and so to some might seem slower than Matlab. For this reason you must vectorize your code as much as possible. The MathWorks themselves have a good document discussing vectorization at http://www.mathworks.com/support/tech-notes/1100/1109.html.
Matlab includes a "Just-In-Time" compiler. This compiler allows the acceleration of for-loops in Matlab to almost native performance with certain restrictions. The JIT must know the return type of all functions called in the loops and so you can't include user functions in the loop of JIT optimized loops. Octave doesn't have a JIT and so to some might seem slower than Matlab. For this reason you must vectorize your code as much as possible. The MathWorks themselves have a good document discussing vectorization at http://www.mathworks.com/support/tech-notes/1100/1109.html.


===Compiler===
== Compiler ==


On a related point, there is no Octave compiler, and so you can't convert your Octave code into a binary for additional speed or distribution. There have been several aborted attempts at creating an Octave compiler. Should the JIT compiler above ever be implemented, an Octave compiler should be more feasible.
On a related point, there is no Octave compiler, and so you can't convert your Octave code into a binary for additional speed or distribution. There have been several aborted attempts at creating an Octave compiler. Should the JIT compiler above ever be implemented, an Octave compiler should be more feasible.


===Graphic handles===
== Graphic handles ==


Up to Octave 2.9.9 there was no support for graphic handles in Octave itself. In the 3.2.N versions of Octave and beyond the support for graphics handles is converging towards full compatibility. The patch function is currently limited to 2-D patches, due to an underlying limitation in gnuplot, but the experimental OpenGL backend is starting to see an implementation of 3-D patches.
Up to Octave 2.9.9 there was no support for graphic handles in Octave itself. In the 3.2.N versions of Octave and beyond, the support for graphics handles is converging towards full compatibility. The patch function is currently limited to 2-D patches, due to an underlying limitation in gnuplot, but the experimental OpenGL backend is starting to see an implementation of 3-D patches.


===GUI functions ===
== GUI functions ==


There are no Matlab compatible GUI functions yet.  This might be an issue if you intend to exchange Octave code with Matlab users. There are a number of bindings from Octave to {{Forge|tcl-octave|Tcl/Tk}}, [http://octaviz.sourceforge.net/index.php? VTK] and {{Forge|zenity}} for example, that can be used for a GUI, but these are not Matlab compatible. Work on a Matlab compatible GUI is in an alpha stage in the QtHandles project, which may form part of a future release of Octave.
There are no Matlab compatible GUI functions yet.  This might be an issue if you intend to exchange Octave code with Matlab users. There are a number of bindings from Octave to {{Forge|tcl-octave|Tcl/Tk}}, [http://octaviz.sourceforge.net/index.php? VTK] and {{Forge|zenity}} for example, that can be used for a GUI, but these are not Matlab compatible. Work on a Matlab compatible GUI is in an alpha stage in the QtHandles project, which may form part of a future release of Octave.


===Simulink===
== Simulink ==


Octave itself includes no Simulink support. Typically the simulink models lag research and are less flexible, so shouldn't really be used in a research environment. However, some Matlab users that try to use Octave complain about this lack.
Octave itself includes no Simulink support. Typically the simulink models lag research and are less flexible, so shouldn't really be used in a research environment. However, some Matlab users that try to use Octave complain about this lack.


===MEX-Files===
== MEX-Files ==


Octave includes an API to the Matlab MEX interface. However, as MEX is an API to the internals of Matlab and the internals of Octave differ from Matlab, there is necessarily a manipulation of the data to convert from a MEX interface to the Octave equivalent. This is notable for all complex matrices, where Matlab stores complex arrays as real and imaginary parts, whereas Octave respects the C99/C++ standards of co-locating the real/imag parts in memory. Also due to the way Matlab allows access to the arrays passed through a pointer, the MEX interface might require copies of arrays (even non complex ones).
Octave includes an API to the Matlab MEX interface. However, as MEX is an API to the internals of Matlab and the internals of Octave differ from Matlab, there is necessarily a manipulation of the data to convert from a MEX interface to the Octave equivalent. This is notable for all complex matrices, where Matlab stores complex arrays as real and imaginary parts, whereas Octave respects the C99/C++ standards of co-locating the real/imag parts in memory. Also due to the way Matlab allows access to the arrays passed through a pointer, the MEX interface might require copies of arrays (even non complex ones).


===Block comments===
== Block comments ==


Block comments denoted by {{Codeline|#{}} and {{Codeline|#&#125;}}  markers (or {{Codeline|%{}} and {{Codeline|%&#125;}}) are supported by Octave with some limitations. The major limitation is that block comments are not supported within [] or {}.
Block comments denoted by {{Codeline|#{}} and {{Codeline|#&#125;}}  markers (or {{Codeline|%{}} and {{Codeline|%&#125;}}) are supported by Octave with some limitations. The major limitation is that block comments are not supported within [] or {}.


===Mat-File format===
== Mat-File format ==


There are some differences in the mat v5 file format accepted by Octave. Matlab recently introduced the "-V7.3" save option which is an HDF5 format which is particularly useful for 64-bit platforms where the standard Matlab format can not correctly save variables. Octave accepts HDF5 files, but is not yet compatible with the "-v7.3" versions produced by Matlab.
There are some differences in the mat v5 file format accepted by Octave. Matlab recently introduced the "-V7.3" save option which is an HDF5 format which is particularly useful for 64-bit platforms where the standard Matlab format can not correctly save variables. Octave accepts HDF5 files, but is not yet compatible with the "-v7.3" versions produced by Matlab.
Line 706: Line 816:
Finally, some multi-byte Unicode characters aren't yet treated in mat-files.
Finally, some multi-byte Unicode characters aren't yet treated in mat-files.


===Profiler===
== Profiler ==


Thanks to Daniel Kraft's 2011 Google Summer of Code project, Octave has a profiler since version 3.6.0. However, at the moment it only produces text output and has its own makeshift interface for hierarchical profiling.
Thanks to Daniel Kraft's 2011 Google Summer of Code project, Octave has a profiler since version 3.6.0. However, at the moment it only produces text output and has its own makeshift interface for hierarchical profiling.


===Toolboxes===
== Toolboxes ==


Octave is a community project and so the toolboxes that exist are donated by those interested in them through [[Octave Forge]]. These might be lacking in certain functionality relative to the Matlab toolboxes, and might not exactly duplicate the Matlab functionality or interface.
Octave is a community project and so the toolboxes that exist are donated by those interested in them through [[Octave Forge]]. These might be lacking in certain functionality relative to the Matlab toolboxes, and might not exactly duplicate the Matlab functionality or interface.


===Short-circuit {{Codeline|&}} and {{Codeline|&#124;}} operators===
== Short-circuit {{Codeline|&}} and {{Codeline|&#124;}} operators ==


The {{Codeline|&}} and {{Codeline|&#124;}} operators in Matlab short-circuit when included in a condition (e.g. an {{Codeline|if}} or {{Codeline|while}} statement) and not otherwise. In Octave only the {{Codeline|&&}} and {{Codeline|&#124;&#124;}} short circuit. Note that this means that
The {{Codeline|&}} and {{Codeline|&#124;}} operators in Matlab short-circuit when included in a condition (e.g. an {{Codeline|if}} or {{Codeline|while}} statement) and not otherwise. In Octave only the {{Codeline|&&}} and {{Codeline|&#124;&#124;}} short circuit. Note that this means that
Line 764: Line 874:
because, despite the name, the {{Codeline|all}} is really returning true if none of the elements of the matrix are zero, and since there are no elements, well, none of them are zero. This is an example of [http://en.wikipedia.org/wiki/Vacuous_truth vacuous truth]. But, somewhere along the line, someone decided that {{Codeline|if ([])}} should be false. Mathworks probably thought it just looks wrong to have {{Codeline|[]}} be true in this context even if you can use logical gymnastics to convince yourself that "all" the elements of an empty matrix are nonzero. Octave however duplicates this behavior for {{Codeline|if}} statements containing empty matrices.
because, despite the name, the {{Codeline|all}} is really returning true if none of the elements of the matrix are zero, and since there are no elements, well, none of them are zero. This is an example of [http://en.wikipedia.org/wiki/Vacuous_truth vacuous truth]. But, somewhere along the line, someone decided that {{Codeline|if ([])}} should be false. Mathworks probably thought it just looks wrong to have {{Codeline|[]}} be true in this context even if you can use logical gymnastics to convince yourself that "all" the elements of an empty matrix are nonzero. Octave however duplicates this behavior for {{Codeline|if}} statements containing empty matrices.


===Solvers for singular, under- and over-determined matrices===
== Solvers for singular, under- and over-determined matrices ==


Matlab's solvers as used by the operators mldivide (\) and mrdivide (/), use a different approach than Octave's in the case of singular, under-, or over-determined matrices. In the case of a singular matrix, Matlab returns the result given by the LU decomposition, even though the underlying solver has flagged the result as erroneous. Octave has made the choice of falling back to a minimum norm solution of matrices that have been flagged as singular which arguably is a better result for these cases.
Matlab's solvers as used by the operators mldivide (\) and mrdivide (/), use a different approach than Octave's in the case of singular, under-, or over-determined matrices. In the case of a singular matrix, Matlab returns the result given by the LU decomposition, even though the underlying solver has flagged the result as erroneous. Octave has made the choice of falling back to a minimum norm solution of matrices that have been flagged as singular which arguably is a better result for these cases.
Line 803: Line 913:
Since the mldivide (\) and mrdivide (/) operators are often part of a more complex expression, where there is no room to react to warnings or flags, it should prefer intelligence (robustness) to speed, and so the Octave developers are firmly of the opinion that Octave's approach for singular, under- and over-determined matrices is a better choice than Matlab's.
Since the mldivide (\) and mrdivide (/) operators are often part of a more complex expression, where there is no room to react to warnings or flags, it should prefer intelligence (robustness) to speed, and so the Octave developers are firmly of the opinion that Octave's approach for singular, under- and over-determined matrices is a better choice than Matlab's.


===Octave extensions===
== Octave extensions ==


The extensions in Octave over MATLAB syntax are very useful, but might cause issues when sharing with Matlab users. A list of the major extensions that should be avoided to be compatible with Matlab are:
The extensions in Octave over MATLAB syntax are very useful, but might cause issues when sharing with Matlab users. A list of the major extensions that should be avoided to be compatible with Matlab are:
Line 854: Line 964:


==Does Octave have a GUI?==
==Does Octave have a GUI?==
Yes! It was officially released with Octave 4.0.0 (May 27th, 2015).  It was
Yes! It was officially released with Octave 4.0.0.  It was
also available since version 3.8.0 has an experimental feature (use the
also available since version 3.8.0 has an experimental feature (use the
{{Codeline|--force-gui}} option to start Octave).
{{Codeline|--force-gui}} option to start Octave).
Line 877: Line 987:
made it free software so we could reuse large chunks of it which were
made it free software so we could reuse large chunks of it which were
incorporated in what is now the Octave GUI.
incorporated in what is now the Octave GUI.
=Graphics: backends and toolkits=
==What are the supported graphics backends?==
The current default is OpenGL, through the "qt" graphics toolkit.  The "ftlk" toolkit also relies on OpenGL.
Alternatively, Gnuplot can be used as a graphics backend by selecting the "gnuplot" graphics toolkit.
==Why did you replace Gnuplot with an OpenGL backend?==
The development of Octave is committed to being both compatible with Matlab and adding additional features. Toward those ends, the development community has chosen to introduce a native OpenGL backend that supports Matlab handle graphics and its uicontrols. Starting with the 3.8 release, Octave uses OpenGL graphics by default (with FLTK widgets in Octave 3.8 and Qt widgets in Octave 4.0 and later).
==Are there any plans to remove the gnuplot backend?==
There are no plans to remove the gnuplot backend. Even though the default graphics toolkit is now "qt", which uses OpenGL graphics with Qt widgets, the gnuplot backend will still be available as long as our users find it useful.
==How can I implement a new graphics backend/toolkit?==
This is one of those times where the best documentation is to read the existing code. We have three different toolkits in Octave now, so there are some examples to draw from.

Navigation menu