Interval package: Difference between revisions

494 bytes added ,  22 March 2015
m
Improved code formatting
m (→‎Installation: Fixed required version number for GNU MPFR)
m (Improved code formatting)
Line 10: Line 10:
|-
|-
| style = "vertical-align: top" |
| style = "vertical-align: top" |
  octave:1> 19 * 0.1 - 2 + 0.1
  <span style="opacity:.5">octave:1> </span>19 * 0.1 - 2 + 0.1
  ans =  1.3878e-16
  ans =  1.3878e-16
| style = "vertical-align: top" |
| style = "vertical-align: top" |
  octave:1> x = infsup ("0.1");
  <span style="opacity:.5">octave:1> </span>x = infsup ("0.1");
  octave:2> 19 * x - 2 + x
  <span style="opacity:.5">octave:2> </span>19 * x - 2 + x
  ans ⊂ [-3.1918911957973251e-16, +1.3877787807814457e-16]
  ans ⊂ [-3.1918911957973251e-16, +1.3877787807814457e-16]
|}
|}
Line 107: Line 107:
== Installation ==
== Installation ==
The interval package is available at Octave Forge [http://octave.sourceforge.net/interval/] and can be installed from within GNU Octave (version ≥ 3.8.2). During installation parts of the package are compiled for the target system, which requires the GNU MPFR development libraries (version ≥ 3.1.0) to be installed.
The interval package is available at Octave Forge [http://octave.sourceforge.net/interval/] and can be installed from within GNU Octave (version ≥ 3.8.2). During installation parts of the package are compiled for the target system, which requires the GNU MPFR development libraries (version ≥ 3.1.0) to be installed.
  octave:1> pkg install -forge interval
  <span style="opacity:.5">octave:1> </span>pkg install -forge interval
  octave:2> pkg load interval
  <span style="opacity:.5">octave:2> </span>pkg load interval


The ''development version'' may be obtained from its mercurial repository. For convenience a Makefile target allows running the package from source.
The ''development version'' may be obtained from its mercurial repository. For convenience a Makefile target allows running the package from source.
  $ hg clone http://hg.code.sf.net/p/octave/interval octave-interval
  hg clone http://hg.code.sf.net/p/octave/interval octave-interval
  $ cd octave-interval; make run
  cd octave-interval; make run


== Quick start introduction ==
== Quick start introduction ==
Line 370: Line 370:
|-
|-
| style = "vertical-align: top" |
| style = "vertical-align: top" |
  octave:1> A = [1, 0; 2, 0];
  <span style="opacity:.5">octave:1> </span>A = [1, 0; 2, 0];
  octave:2> A \ [3; 0]    # no solution
  <span style="opacity:.5">octave:2> </span>A \ [3; 0]    # no solution
  warning: matrix singular to machine precision, rcond = 0
  warning: matrix singular to machine precision, rcond = 0
  ans =
  ans =
Line 378: Line 378:
     0.00000
     0.00000
   
   
  octave:3> A \ [4; 8]    # many solutions
  <span style="opacity:.5">octave:3> </span>A \ [4; 8]    # many solutions
  ans =
  ans =
   
   
Line 384: Line 384:
     0
     0
| style = "vertical-align: top" |
| style = "vertical-align: top" |
  octave:4> A = infsup (A);
  <span style="opacity:.5">octave:4> </span>A = infsup (A);
  octave:5> A \ [3; 0]    # no solution
  <span style="opacity:.5">octave:5> </span>A \ [3; 0]    # no solution
  ans = 2×1 interval vector
  ans = 2×1 interval vector
   
   
Line 391: Line 391:
     [Empty]
     [Empty]
   
   
  octave:6> A \ [4; 8]    # many solutions
  <span style="opacity:.5">octave:6> </span>A \ [4; 8]    # many solutions
  ans = 2×1 interval vector
  ans = 2×1 interval vector
   
   
Line 401: Line 401:
Due to the nature of set-based interval arithmetic, one should never observe errors (in the sense of raised GNU Octave error messages) during computation. If you do, there either is a bug in the code or there are unsupported data types. Arithmetic operations which are not defined for (parts of) their input, simply ignore anything that is outside of their domain.
Due to the nature of set-based interval arithmetic, one should never observe errors (in the sense of raised GNU Octave error messages) during computation. If you do, there either is a bug in the code or there are unsupported data types. Arithmetic operations which are not defined for (parts of) their input, simply ignore anything that is outside of their domain.


  octave:1> infsup (2, 3) / 0
  <span style="opacity:.5">octave:1> </span>infsup (2, 3) / 0
  ans = [Empty]
  ans = [Empty]
  octave:2> infsup (0) ^ infsup (0)
  <span style="opacity:.5">octave:2> </span>infsup (0) ^ infsup (0)
  ans = [Empty]
  ans = [Empty]


However, the interval constructors can produce errors depending on the input. The <code>infsup</code> constructor will fail if the interval boundaries are invalid. Contrariwise, the <code>infsupdec</code> constructor will only issue a warning and return a [NaI], which will propagate and survive through computations.
However, the interval constructors can produce errors depending on the input. The <code>infsup</code> constructor will fail if the interval boundaries are invalid. Contrariwise, the <code>infsupdec</code> constructor will only issue a warning and return a [NaI], which will propagate and survive through computations.


  octave:3> infsup (3, 2) + 1
  <span style="opacity:.5">octave:3> </span>infsup (3, 2) + 1
  error: illegal interval boundaries: infimum greater than supremum
  error: illegal interval boundaries: infimum greater than supremum
  ''… (call stack) …''
  ''… (call stack) …''
  octave:3> infsupdec (3, 2) + 1
  <span style="opacity:.5">octave:3> </span>infsupdec (3, 2) + 1
  warning: illegal interval boundaries: infimum greater than supremum
  warning: illegal interval boundaries: infimum greater than supremum
  ans = [NaI]
  ans = [NaI]
Line 494: Line 494:
* Basic operations can be found in both packages, but the availability of special functions depends
* Basic operations can be found in both packages, but the availability of special functions depends


In GNU Octave the interval package can also be run together with INTLAB, as the following script demonstrates:
{{Code|In GNU Octave the interval package can also be run alongside INTLAB.|<syntaxhighlight lang="octave">
 
  # INTLAB intervals
  # INTLAB intervals
  A1 = infsup (2, 3);
  A1 = infsup (2, 3);
Line 511: Line 510:
  # Computation without INTLAB
  # Computation without INTLAB
  A2 + B2 * C2
  A2 + B2 * C2
</syntaxhighlight>
}}


== Related work ==
== Related work ==
240

edits