Changes

Jump to navigation Jump to search

Interval package

20 bytes added, 17:19, 30 March 2015
m
Updated interval output with less decimal digits and zero before the decimal point
<span style="opacity:.5">octave:1> </span>x = infsup ("0.1");
<span style="opacity:.5">octave:2> </span>19 * x - 2 + x
ans ⊂ [-3.1918911957973251e191891195797326e-16, +1.3877787807814457e-16]
|}
infsupdec (1, 2) # [1, 2]_com
infsupdec ("3", "4") # [3, 4]_com
infsupdec ("1.1") # [1.0999999999999998, 1.1000000000000001100000000000001]_com
infsupdec ("5.8e-17")
# [5.799999999999999e-17, 5.800000000000001e-17]_com
midrad (12, 3) # [9, 15]_com
midrad ("4.2", "1e-7") # [4.199999899999999, 4.2000001000000005200000100000001]_comhull (3, 42, "19.3", "-2.3") # [-2.3000000000000003300000000000001, +42]_trv_co
hull ("pi", "e") # [2.718281828459045, 3.1415926535897936]_trv
</syntaxhighlight>
{{Code|Beware of the conversion pitfall|<syntaxhighlight lang="octave">
## The numeric constant “0.2” 3” is an approximation of the## decimal number 0.23. An interval around this approximation## will not contain the decimal number 0.23.infsupdec (0.23) # [0.2000000000000000129999999999999998, 0.2000000000000000229999999999999999]_com## However, passing the decimal number 0.2 3 as a string
## to the interval constructor will create an interval which
## actually encloses the decimal number.
infsupdec ("0.23") # [0.1999999999999999829999999999999998, 0.200000000000000023000000000000001]_com
</syntaxhighlight>
}}
# [4, 5] [9, 10] [2, 3]
infsupdec (["0.1"; "0.2"; "0.3"; "0.4"; "0.5"])
# [0.09999999999999999, 0.100000000000000011000000000000001]_com # [0.19999999999999998, 0.200000000000000022000000000000001]_com # [0.29999999999999998, 0.300000000000000053000000000000001]_com # [0.39999999999999996, 0.400000000000000034000000000000001]_com # [0.5]_com
infsup ({1, eps; "4/7", "pi"}, {2, 1; "e", "0xff"})
# [1, 2] [2.220446049250313e-16, 1] # [0.5714285714285713, 2.7182818284590456] [3.1415926535897931141592653589793, 255]
</syntaxhighlight>
}}
{{Code|Examples of using interval arithmetic functions|<syntaxhighlight lang="octave">
sin (infsupdec (0.5)) # [.479425538604202944794255386042029, .479425538604203014794255386042031]_com
pow (infsupdec (2), infsupdec (3, 4)) # [8, 16]_com
atan2 (infsupdec (1), infsupdec (1))
# [0] [0] [1]
B = inv (A)
# [0] [0.25] [-1.5, 0] # [0.5] [-0.125] [-1.5, -0.75] # [0] [0] [1]
A * B
# [1] [0] [-1.5, +1.5]
# [4] [9] [2]
c = A \ [3; 4; 5]
# [0.1833333333333332618333333333333315, 0.1833333333333334918333333333333358] # [0.4333333333333332943333333333333318, 0.4333333333333334143333333333333346] # [0.1833333333333331518333333333333307, 0.1833333333333333818333333333333355]
A * c
# [2.99999999999999829999999999999964, 3.00000000000000180000000000000036] # [3.99999999999999829999999999999964, 4.0000000000000018000000000000004] # [4.9999999999999982999999999999997, 5.0000000000000018000000000000003]
</syntaxhighlight>
}}
{{Code|Examples of using the decoration system|<syntaxhighlight lang="octave">
x = infsupdec (3, 4) # [3, 4]_com
y = x - 3.5 # [-0.5, +0.5]_com
## The square root function ignores any negative part of the input,
## but the decoration indicates whether this has or has not happened.
sqrt (x) # [1.7320508075688771732050807568877, 2]_comsqrt (y) # [0, 0.7071067811865476]_trv
</syntaxhighlight>
}}
{{Code|Examples of different formats during interval construction|<syntaxhighlight lang="octave">
infsup ("0x1.999999999999Ap-4") # hex-form
# [0.1, 0.100000000000000011000000000000001]
infsup ("1/3", "7/9") # rational form
# [0.333333333333333313333333333333333, 0.7777777777777778]
infsup ("121.2?") # uncertain form
# [121.14999999999999, 121.25]
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))
x ⊂ [1.6128979635153646, 2.7148547265657915714854726565793]
<span style="opacity:.5">octave:2> </span>y = powrev2 (infsup ("[2.14, 2.5]"), infsup (2, 3))
y ⊂ [0.7564707973660299, 1.44401139784032844440113978403289]
=== Tips & Tricks ===
<span style="opacity:.5">octave:1> </span>infsupdec ("17.7") + 1
ans ⊂ [18.699999999999999, 18.70000000000000370000000000001]_com
<span style="opacity:.5">octave:2> </span>ans + "[0, 2]"
ans ⊂ [18.699999999999999, 20.70000000000000370000000000001]_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>.
240

edits

Navigation menu