|
3.1.7 Advanced Topic: Interval Arithmetic

Representations of real intervals.
This represents all numbers between and .
In[1]:= Interval[{-2, 5}]
Out[1]= 
The square of any number between and is always between 0 and 25.
In[2]:= Interval[{-2, 5}]^2
Out[2]= 
Taking the reciprocal gives two distinct intervals.
In[3]:= 1/Interval[{-2, 5}]
Out[3]= 
Abs folds the intervals back together again.
In[4]:= Abs[%]
Out[4]= 
You can use intervals in many kinds of functions.
In[5]:= Solve[3 x + 2 == Interval[{-2, 5}], x]
Out[5]= 
Some functions automatically generate intervals.
In[6]:= Limit[Sin[1/x], x -> 0]
Out[6]= 

Operations on intervals.
This finds the overlap of the two intervals.
In[7]:= IntervalIntersection[Interval[{3, 7}], Interval[{-2, 5}]]
Out[7]= 
You can use Max and Min to find the end points of intervals.
In[8]:= Max[%]
Out[8]= 
This finds out which of a list of intervals contains the point 7.
In[9]:= IntervalMemberQ[
Table[Interval[{i, i+1}], {i, 1, 20, 3}], 7]
Out[9]= 
You can use intervals not only with exact quantities but also with approximate numbers. Even with machine-precision numbers, Mathematica always tries to do rounding in such a way as to preserve the validity of results.
This shows explicitly the interval treated by Mathematica as the machine-precision number 0.
In[10]:= Interval[0.]
Out[10]= 
This shows the corresponding interval around 100., shifted back to zero.
In[11]:= Interval[100.] - 100
Out[11]= 
The same kind of thing works with numbers of any precision.
In[12]:= Interval[N[Pi, 50]] - Pi
Out[12]= 
With ordinary machine-precision arithmetic, this computation gives an incorrect result.
In[13]:= Sin[N[Pi]]
Out[13]= 
The interval generated here, however, includes the correct value of 0.
In[14]:= Sin[Interval[N[Pi]]]
Out[14]= 
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT. SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION. |