Interval package: Difference between revisions

Updated interval output
(Updated interval output)
Line 17: Line 17:
  octave:1> x = infsup ("0.1");
  octave:1> x = infsup ("0.1");
  octave:2> 19 * x - 2 + x
  octave:2> 19 * x - 2 + x
  ans = [-3.1918911957973251e-16, +1.3877787807814457e-16]
  ans [-3.1918911957973251e-16, +1.3877787807814457e-16]
|}
|}


Line 54: Line 54:
  ans = [3, 4]
  ans = [3, 4]
  octave:4> infsup ("1.1")
  octave:4> infsup ("1.1")
  ans = [1.0999999999999998, 1.1000000000000001]
  ans [1.0999999999999998, 1.1000000000000001]
  octave:5> infsup ("[5, 6.5]")
  octave:5> infsup ("[5, 6.5]")
  ans = [5, 6.5]
  ans = [5, 6.5]
  octave:6> infsup ("[5.8e-17]")
  octave:6> infsup ("[5.8e-17]")
  ans = [5.799999999999999e-17, 5.800000000000001e-17]
  ans [5.799999999999999e-17, 5.800000000000001e-17]


It is possible to access the exact numeric interval boundaries with the functions <code>inf</code> and <code>sup</code>. The default text representation of intervals can be created with <code>intervaltotext</code>. The default text representation is not guaranteed to be exact (see function <code>intervaltoexact</code>), because this would massively spam console output. For example, the exact text representation of <code>realmin</code> would be over 700 decimal places long! However, the default text representation is correct as it guarantees to contain the actual boundaries and is accurate enough to separate different boundaries.
It is possible to access the exact numeric interval boundaries with the functions <code>inf</code> and <code>sup</code>. The default text representation of intervals can be created with <code>intervaltotext</code>. The default text representation is not guaranteed to be exact (see function <code>intervaltoexact</code>), because this would massively spam console output. For example, the exact text representation of <code>realmin</code> would be over 700 decimal places long! However, the default text representation is correct as it guarantees to contain the actual boundaries and is accurate enough to separate different boundaries.


  octave:7> infsup (1, 1 + eps)
  octave:7> infsup (1, 1 + eps)
  ans = [1, 1.0000000000000003]
  ans [1, 1.0000000000000003]
  octave:8> infsup (1, 1 + 2 * eps)
  octave:8> infsup (1, 1 + 2 * eps)
  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.


  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]
  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:11> infsup ("17.7") + 1
  ans = [18.699999999999999, 18.700000000000003]
  ans [18.699999999999999, 18.700000000000003]
  octave:12> ans + "[0, 2]"
  octave:12> ans + "[0, 2]"
  ans = [18.699999999999999, 20.700000000000003]
  ans [18.699999999999999, 20.700000000000003]


=== Decorations ===
=== Decorations ===
Line 139: Line 139:


  octave:1> sin (infsup (0.5))
  octave:1> sin (infsup (0.5))
  ans = [.47942553860420294, .47942553860420307]
  ans [.47942553860420294, .47942553860420307]
  octave:2> pow (infsup (2), infsup (3, 4))
  octave:2> pow (infsup (2), infsup (3, 4))
  ans = [8, 16]
  ans = [8, 16]
  octave:3> atan2 (infsup (1), infsup (1))
  octave:3> atan2 (infsup (1), infsup (1))
  ans = [.7853981633974482, .7853981633974484]
  ans [.7853981633974482, .7853981633974484]


=== Reverse arithmetic operations ===
=== Reverse arithmetic operations ===
Line 152: Line 152:
In the following example, we compute the constraints for base and exponent of the power function <code>pow</code> as shown in the figure.
In the following example, we compute the constraints for base and exponent of the power function <code>pow</code> as shown in the figure.
  octave:1> x = powrev1 (infsup ("[1.1, 1.45]"), infsup (2, 3))
  octave:1> x = powrev1 (infsup ("[1.1, 1.45]"), infsup (2, 3))
  x = [1.6128979635153644, 2.7148547265657923]
  x [1.6128979635153644, 2.7148547265657923]
  octave:2> y = powrev2 (infsup ("[2.14, 2.5]"), infsup (2, 3))
  octave:2> y = powrev2 (infsup ("[2.14, 2.5]"), infsup (2, 3))
  y = [.7564707973660299, 1.4440113978403289]
  y [.7564707973660299, 1.4440113978403289]


=== Numerical operations ===
=== Numerical operations ===
240

edits