[Tutor] class uncertainty

Christopher Smith csmith@blakeschool.org
Tue, 28 Aug 2001 08:06:32 -0500


hnowak@cuci.nl writes:
>>===== Original Message From "Christopher Smith" <csmith@blakeschool.org> 
>=====
>>I've created a class which keeps track of the uncertainty in a number and
>>subsequent calculations performed with that number.  It works like this:
>>
>>u=uncertainty #shorten the name
>>
>># define physical measurements
>># with +/-1 in last digit by default
>>p=u('1.0')
>>R=u('.0821')
>>T=u('298')
>>
>># define a physical measurement witha larger uncertainty
>>n=u('1.0,.15')
>>
>>#do the calculation and look at results
>>v=n*R*T/p
>>print v
>>print v[0]
>>print v[1]
>>
>>#results are
>># 24 +/- 9
>># 24.4658
>># 9.31980083228
>
>Looks neat... why is u() taking strings, though?

To avoid missing an intended trailing 0 (5.00) looking like 5.0)
or excessive digits b/c of floating representation issues (5.1 looking 
like 5.09999999996 to the function).

/c
>