Interval package: Difference between revisions

m
→‎Input and output: Added hint for command syntax
m (→‎Input and output: Added hint for command syntax)
Line 130: Line 130:
  ans ⊂ [1, 1.0000000000000005]
  ans ⊂ [1, 1.0000000000000005]


Warning: Decimal fractions as well as numbers of high magnitude (> 2<sup>53</sup>) should always be passed as a string to the constructor. Otherwise it is possible, that GNU Octave introduces conversion errors when the numeric literal is converted into floating-point format '''before''' it is passed to the constructor.
Warning: Decimal fractions as well as numbers of high magnitude (> 2<sup>53</sup>) should always be passed as a string to the constructor. Otherwise it is possible, that GNU Octave introduces conversion errors when the numeric literal is converted into floating-point format '''before''' it is passed to the constructor. In simple cases it may help to construct intervals with the [https://www.gnu.org/software/octave/doc/interpreter/Commands.html#Commands command syntax].


  octave:9> infsup (<span style = "color:red">0.2</span>)
  octave:9> infsup (<span style = "color:red">0.2</span>)
  ans ⊂ [.20000000000000001, .20000000000000002]
  ans ⊂ [.20000000000000001, .20000000000000002]
  octave:10> infsup (<span style = "color:green">"0.2"</span>)
  octave:10> infsup (<span style = "color:green">"0.2"</span>)
ans ⊂ [.19999999999999998, .20000000000000002]
octave:11> infsup <span style = "color:green">0.2</span>
  ans ⊂ [.19999999999999998, .20000000000000002]
  ans ⊂ [.19999999999999998, .20000000000000002]


For convenience it is possible to implicitly call the interval constructor during all interval operations if at least one input already is an interval object.
For convenience it is possible to implicitly call the interval constructor during all interval operations if at least one input already is an interval object.


  octave:11> infsup ("17.7") + 1
  octave:12> infsup ("17.7") + 1
  ans ⊂ [18.699999999999999, 18.700000000000003]
  ans ⊂ [18.699999999999999, 18.700000000000003]
  octave:12> ans + "[0, 2]"
  octave:13> ans + "[0, 2]"
  ans ⊂ [18.699999999999999, 20.700000000000003]
  ans ⊂ [18.699999999999999, 20.700000000000003]


Line 154: Line 156:
** <code>''E ''</code> is either empty or an exponent field comprising the character <code>e</code> followed by a decimal integer exponent (base 10).
** <code>''E ''</code> is either empty or an exponent field comprising the character <code>e</code> followed by a decimal integer exponent (base 10).


  octave:13> infsup ("0x1.999999999999Ap-4")
  octave:14> infsup ("0x1.999999999999Ap-4")
  ans ⊂ [.1, .10000000000000001]
  ans ⊂ [.1, .10000000000000001]
  octave:14> infsup ("1/3", "7/9")
  octave:15> infsup ("1/3", "7/9")
  ans ⊂ [.33333333333333331, .7777777777777778]
  ans ⊂ [.33333333333333331, .7777777777777778]
  octave:15> infsup ("121.2?")
  octave:16> infsup ("121.2?")
  ans ⊂ [121.14999999999999, 121.25]
  ans ⊂ [121.14999999999999, 121.25]
  octave:16> infsup ("5?32e2")
  octave:17> infsup ("5?32e2")
  ans = [-2700, +3700]
  ans = [-2700, +3700]
  octave:17> infsup ("-42??u")
  octave:18> infsup ("-42??u")
  ans = [-42, +Inf]
  ans = [-42, +Inf]


==== Interval vectors and matrices ====
==== Interval vectors and matrices ====
Vectors and matrices of intervals can be created by passing numerical matrices, char vectors or cell arrays to the <code>infsup</code> constructor. With cell arrays it is also possible to mix several types of boundaries.
Vectors and matrices of intervals can be created by passing numerical matrices, char vectors or cell arrays to the <code>infsup</code> constructor. With cell arrays it is also possible to mix several types of boundaries.
  octave:18> M = infsup (magic (3))
  octave:19> M = infsup (magic (3))
  M = 3×3 interval matrix
  M = 3×3 interval matrix
   
   
Line 174: Line 176:
     [4]  [9]  [2]
     [4]  [9]  [2]
   
   
  octave:19> infsup (magic (3), magic (3) + 1)
  octave:20> infsup (magic (3), magic (3) + 1)
  ans = 3×3 interval matrix
  ans = 3×3 interval matrix
   
   
Line 181: Line 183:
     [4, 5]  [9, 10]  [2, 3]
     [4, 5]  [9, 10]  [2, 3]
   
   
  octave:20> infsup (["0.1"; "0.2"; "0.3"; "0.4"; "0.5"])
  octave:21> infsup (["0.1"; "0.2"; "0.3"; "0.4"; "0.5"])
  ans ⊂ 5×1 interval vector
  ans ⊂ 5×1 interval vector
   
   
Line 190: Line 192:
                                         [.5]
                                         [.5]
   
   
  octave:21> infsup ({1, eps; "4/7", "pi"}, {2, 1; "e", "0xff"})
  octave:22> infsup ({1, eps; "4/7", "pi"}, {2, 1; "e", "0xff"})
  ans ⊂ 2×2 interval matrix
  ans ⊂ 2×2 interval matrix
   
   
Line 197: Line 199:


When matrices are resized using subscripted assignment, any implicit new matrix elements will carry an empty interval.
When matrices are resized using subscripted assignment, any implicit new matrix elements will carry an empty interval.
  octave:22> M (4, 4) = 42
  octave:23> M (4, 4) = 42
  M = 4×4 interval matrix
  M = 4×4 interval matrix
   
   
Line 206: Line 208:


Note: Whilst most functions (<code>size</code>, <code>isvector</code>, <code>ismatrix</code>, …) work as expected on interval data types, the function <code>'''isempty'''</code> is evaluated element-wise and checks if an interval equals the empty set.
Note: Whilst most functions (<code>size</code>, <code>isvector</code>, <code>ismatrix</code>, …) work as expected on interval data types, the function <code>'''isempty'''</code> is evaluated element-wise and checks if an interval equals the empty set.
  octave:23> builtin ("isempty", empty ()), isempty (empty ())
  octave:24> builtin ("isempty", empty ()), isempty (empty ())
  ans = 0
  ans = 0
  ans =  1
  ans =  1
240

edits