Interval package: Difference between revisions

m
Updated interval output with less decimal digits and zero before the decimal point
m (→‎Error handling: Added information for fixing the warning reasons)
m (Updated interval output with less decimal digits and zero before the decimal point)
Line 15: Line 15:
  <span style="opacity:.5">octave:1> </span>x = infsup ("0.1");
  <span style="opacity:.5">octave:1> </span>x = infsup ("0.1");
  <span style="opacity:.5">octave:2> </span>19 * x - 2 + x
  <span style="opacity:.5">octave:2> </span>19 * x - 2 + x
  ans ⊂ [-3.1918911957973251e-16, +1.3877787807814457e-16]
  ans ⊂ [-3.191891195797326e-16, +1.3877787807814457e-16]
|}
|}


Line 123: Line 123:
infsupdec (1, 2) # [1, 2]_com
infsupdec (1, 2) # [1, 2]_com
infsupdec ("3", "4") # [3, 4]_com
infsupdec ("3", "4") # [3, 4]_com
infsupdec ("1.1") # [1.0999999999999998, 1.1000000000000001]_com
infsupdec ("1.1") # [1.0999999999999998, 1.100000000000001]_com
infsupdec ("5.8e-17")
infsupdec ("5.8e-17")
   # [5.799999999999999e-17, 5.800000000000001e-17]_com
   # [5.799999999999999e-17, 5.800000000000001e-17]_com
midrad (12, 3) # [9, 15]_com
midrad (12, 3) # [9, 15]_com
midrad ("4.2", "1e-7") # [4.199999899999999, 4.2000001000000005]_com
midrad ("4.2", "1e-7") # [4.199999899999999, 4.200000100000001]_com
hull (3, 42, "19.3", "-2.3") # [-2.3000000000000003, +42]_trv
hull (3, 42, "19.3", "-2.3") # [-2.300000000000001, +42]_co
hull ("pi", "e") # [2.718281828459045, 3.1415926535897936]_trv
hull ("pi", "e") # [2.718281828459045, 3.1415926535897936]_trv
</syntaxhighlight>
</syntaxhighlight>
Line 138: Line 138:


{{Code|Beware of the conversion pitfall|<syntaxhighlight lang="octave">
{{Code|Beware of the conversion pitfall|<syntaxhighlight lang="octave">
## The numeric constant “0.2” is an approximation of the
## The numeric constant “0.3” is an approximation of the
## decimal number 0.2.  An interval around this approximation
## decimal number 0.3.  An interval around this approximation
## will not contain the decimal number 0.2.
## will not contain the decimal number 0.3.
infsupdec (0.2) # [.20000000000000001, .20000000000000002]_com
infsupdec (0.3) # [0.29999999999999998, 0.29999999999999999]_com
## However, passing the decimal number 0.2 as a string
## However, passing the decimal number 0.3 as a string
## to the interval constructor will create an interval which
## to the interval constructor will create an interval which
## actually encloses the decimal number.
## actually encloses the decimal number.
infsupdec ("0.2") # [.19999999999999998, .20000000000000002]_com
infsupdec ("0.3") # [0.29999999999999998, 0.3000000000000001]_com
</syntaxhighlight>
</syntaxhighlight>
}}
}}
Line 164: Line 164:
   # [4, 5]  [9, 10]  [2, 3]
   # [4, 5]  [9, 10]  [2, 3]
infsupdec (["0.1"; "0.2"; "0.3"; "0.4"; "0.5"])
infsupdec (["0.1"; "0.2"; "0.3"; "0.4"; "0.5"])
   # [.09999999999999999, .10000000000000001]_com
   # [0.09999999999999999, 0.1000000000000001]_com
   # [.19999999999999998, .20000000000000002]_com
   # [0.19999999999999998, 0.2000000000000001]_com
   # [.29999999999999998, .30000000000000005]_com
   # [0.29999999999999998, 0.3000000000000001]_com
   # [.39999999999999996, .40000000000000003]_com
   # [0.39999999999999996, 0.4000000000000001]_com
   #                                    [.5]_com
   #                                    [0.5]_com
infsup ({1, eps; "4/7", "pi"}, {2, 1; "e", "0xff"})
infsup ({1, eps; "4/7", "pi"}, {2, 1; "e", "0xff"})
   #                                 [1, 2]  [2.220446049250313e-16, 1]
   #                                   [1, 2]  [2.220446049250313e-16, 1]
   # [.5714285714285713, 2.7182818284590456]   [3.1415926535897931, 255]
   # [0.5714285714285713, 2.7182818284590456]     [3.141592653589793, 255]
</syntaxhighlight>
</syntaxhighlight>
}}
}}
Line 183: Line 183:


{{Code|Examples of using interval arithmetic functions|<syntaxhighlight lang="octave">
{{Code|Examples of using interval arithmetic functions|<syntaxhighlight lang="octave">
sin (infsupdec (0.5)) # [.47942553860420294, .47942553860420301]_com
sin (infsupdec (0.5)) # [.4794255386042029, .4794255386042031]_com
pow (infsupdec (2), infsupdec (3, 4)) # [8, 16]_com
pow (infsupdec (2), infsupdec (3, 4)) # [8, 16]_com
atan2 (infsupdec (1), infsupdec (1))
atan2 (infsupdec (1), infsupdec (1))
Line 216: Line 216:
   # [0]  [0]      [1]
   # [0]  [0]      [1]
B = inv (A)
B = inv (A)
   # [0]    [.25]     [-1.5, 0]
   #   [0]    [0.25]       [-1.5, 0]
   # [.5]  [-.125]  [-1.5, -.75]
   # [0.5]  [-0.125]  [-1.5, -0.75]
   # [0]       [0]           [1]
   #   [0]       [0]             [1]
A * B
A * B
   # [1]  [0]  [-1.5, +1.5]
   # [1]  [0]  [-1.5, +1.5]
Line 229: Line 229:
   # [4]  [9]  [2]
   # [4]  [9]  [2]
c = A \ [3; 4; 5]
c = A \ [3; 4; 5]
   # [.18333333333333326, .18333333333333349]
   # [0.18333333333333315, 0.18333333333333358]
   # [.43333333333333329, .43333333333333341]
   # [0.43333333333333318, 0.43333333333333346]
   # [.18333333333333315, .18333333333333338]
   # [0.18333333333333307, 0.18333333333333355]
A * c
A * c
   # [2.9999999999999982, 3.0000000000000018]
   # [2.9999999999999964, 3.0000000000000036]
   # [3.9999999999999982, 4.0000000000000018]
   # [3.9999999999999964, 4.000000000000004]
   # [4.9999999999999982, 5.0000000000000018]
   #   [4.999999999999997, 5.000000000000003]
</syntaxhighlight>
</syntaxhighlight>
}}
}}
Line 363: Line 363:
{{Code|Examples of using the decoration system|<syntaxhighlight lang="octave">
{{Code|Examples of using the decoration system|<syntaxhighlight lang="octave">
x = infsupdec (3, 4) # [3, 4]_com
x = infsupdec (3, 4) # [3, 4]_com
y = x - 3.5 # [-.5, +.5]_com
y = x - 3.5 # [-0.5, +0.5]_com
## The square root function ignores any negative part of the input,
## The square root function ignores any negative part of the input,
## but the decoration indicates whether this has or has not happened.
## but the decoration indicates whether this has or has not happened.
sqrt (x) # [1.7320508075688771, 2]_com
sqrt (x) # [1.732050807568877, 2]_com
sqrt (y) # [0, .7071067811865476]_trv
sqrt (y) # [0, 0.7071067811865476]_trv
</syntaxhighlight>
</syntaxhighlight>
}}
}}
Line 383: Line 383:
{{Code|Examples of different formats during interval construction|<syntaxhighlight lang="octave">
{{Code|Examples of different formats during interval construction|<syntaxhighlight lang="octave">
infsup ("0x1.999999999999Ap-4") # hex-form
infsup ("0x1.999999999999Ap-4") # hex-form
   # [.1, .10000000000000001]
   # [0.1, 0.1000000000000001]
infsup ("1/3", "7/9") # rational form
infsup ("1/3", "7/9") # rational form
   # [.33333333333333331, .7777777777777778]
   # [0.3333333333333333, 0.7777777777777778]
infsup ("121.2?") # uncertain form
infsup ("121.2?") # uncertain form
   # [121.14999999999999, 121.25]
   # [121.14999999999999, 121.25]
Line 402: Line 402:
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.
  <span style="opacity:.5">octave:1> </span>x = powrev1 (infsup ("[1.1, 1.45]"), infsup (2, 3))
  <span style="opacity:.5">octave:1> </span>x = powrev1 (infsup ("[1.1, 1.45]"), infsup (2, 3))
  x ⊂ [1.6128979635153646, 2.7148547265657915]
  x ⊂ [1.6128979635153646, 2.714854726565793]
  <span style="opacity:.5">octave:2> </span>y = powrev2 (infsup ("[2.14, 2.5]"), infsup (2, 3))
  <span style="opacity:.5">octave:2> </span>y = powrev2 (infsup ("[2.14, 2.5]"), infsup (2, 3))
  y ⊂ [.7564707973660299, 1.4440113978403284]
  y ⊂ [0.7564707973660299, 1.4440113978403289]


=== Tips & Tricks ===
=== Tips & Tricks ===
Line 410: Line 410:


  <span style="opacity:.5">octave:1> </span>infsupdec ("17.7") + 1
  <span style="opacity:.5">octave:1> </span>infsupdec ("17.7") + 1
  ans ⊂ [18.699999999999999, 18.700000000000003]_com
  ans ⊂ [18.699999999999999, 18.70000000000001]_com
  <span style="opacity:.5">octave:2> </span>ans + "[0, 2]"
  <span style="opacity:.5">octave:2> </span>ans + "[0, 2]"
  ans ⊂ [18.699999999999999, 20.700000000000003]_com
  ans ⊂ [18.699999999999999, 20.70000000000001]_com


Interval functions with only one argument can be called by using property syntax, e. g. <code>x.inf</code>, <code>x.sup</code> or even <code>x.sqr</code>.
Interval functions with only one argument can be called by using property syntax, e. g. <code>x.inf</code>, <code>x.sup</code> or even <code>x.sqr</code>.
240

edits