Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20493 > unrolled thread

format a measurement result and its error in "scientific" way

Started byDaniel Fetchinson <fetchinson@googlemail.com>
First post2012-02-16 01:18 +0100
Last post2012-02-17 12:16 +0100
Articles 5 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  format a measurement result and its error in "scientific" way Daniel Fetchinson <fetchinson@googlemail.com> - 2012-02-16 01:18 +0100
    Re: format a measurement result and its error in "scientific" way jmfauth <wxjmfauth@gmail.com> - 2012-02-17 01:17 -0800
      Re: format a measurement result and its error in "scientific" way Daniel Fetchinson <fetchinson@googlemail.com> - 2012-02-17 11:03 +0100
        Re: format a measurement result and its error in "scientific" way jmfauth <wxjmfauth@gmail.com> - 2012-02-17 04:13 -0800
    Re: format a measurement result and its error in "scientific" way Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-02-17 12:16 +0100

#20493 — format a measurement result and its error in "scientific" way

FromDaniel Fetchinson <fetchinson@googlemail.com>
Date2012-02-16 01:18 +0100
Subjectformat a measurement result and its error in "scientific" way
Message-ID<mailman.5869.1329351490.27778.python-list@python.org>
Hi folks, often times in science one expresses a value (say
1.03789291) and its error (say 0.00089) in a short way by parentheses
like so: 1.0379(9)

One can vary things a bit, but let's take the simplest case when we
only keep 1 digit of the error (and round it of course) and round the
value correspondingly. I've been searching around for a simple
function that would take 2 float arguments and would return a string
but didn't find anything although something tells me it's been done a
gazillion times.

What would be the simplest such function?

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown

[toc] | [next] | [standalone]


#20542

Fromjmfauth <wxjmfauth@gmail.com>
Date2012-02-17 01:17 -0800
Message-ID<955b9613-2386-40ef-bbf7-c60ef623b0cd@k6g2000vbz.googlegroups.com>
In reply to#20493
On 16 fév, 01:18, Daniel Fetchinson <fetchin...@googlemail.com> wrote:
> Hi folks, often times in science one expresses a value (say
> 1.03789291) and its error (say 0.00089) in a short way by parentheses
> like so: 1.0379(9)
>

Before swallowing any Python solution, you should
realize, the values (value, error) you are using are
a non sense :

1.03789291 +/- 0.00089

You express "more precision" in the value than
in the error.

---

As ex, in a 1.234(5) notation, the "()" is usually
used to indicate the accuracy of the digit in "()".

Eg 1.345(7)

Typographically, the "()" is sometimes replaced by
a bold digit ou a subscripted digit.

jmf

[toc] | [prev] | [next] | [standalone]


#20546

FromDaniel Fetchinson <fetchinson@googlemail.com>
Date2012-02-17 11:03 +0100
Message-ID<mailman.5914.1329473025.27778.python-list@python.org>
In reply to#20542
>> Hi folks, often times in science one expresses a value (say
>> 1.03789291) and its error (say 0.00089) in a short way by parentheses
>> like so: 1.0379(9)
>
> Before swallowing any Python solution, you should
> realize, the values (value, error) you are using are
> a non sense :
>
> 1.03789291 +/- 0.00089
>
> You express "more precision" in the value than
> in the error.

My impression is that you didn't understand the original problem:
given an arbitrary value to arbitrary digits and an arbitrary error,
find the relevant number of digits for the value that makes sense for
the given error. So what you call "non sense" is part of the problem
to be solved.

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown

[toc] | [prev] | [next] | [standalone]


#20550

Fromjmfauth <wxjmfauth@gmail.com>
Date2012-02-17 04:13 -0800
Message-ID<e77a062a-3c6d-422f-b2bb-b0770c64e796@l16g2000vbl.googlegroups.com>
In reply to#20546
On 17 fév, 11:03, Daniel Fetchinson <fetchin...@googlemail.com> wrote:
> >> Hi folks, often times in science one expresses a value (say
> >> 1.03789291) and its error (say 0.00089) in a short way by parentheses
> >> like so: 1.0379(9)
>
> > Before swallowing any Python solution, you should
> > realize, the values (value, error) you are using are
> > a non sense :
>
> > 1.03789291 +/- 0.00089
>
> > You express "more precision" in the value than
> > in the error.
>
> My impression is that you didn't understand the original problem:
> given an arbitrary value to arbitrary digits and an arbitrary error,
> find the relevant number of digits for the value that makes sense for
> the given error. So what you call "non sense" is part of the problem
> to be solved.
>

I do not know where these numbers (value, error) are
coming from. But, when the value and the error
have not the same "precision", there is already
something wrong somewhere.
And this, *prior* to any representation of these
values/numbers.

jmf

[toc] | [prev] | [next] | [standalone]


#20549

FromUlrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Date2012-02-17 12:16 +0100
Message-ID<nhp119-fdg.ln1@satorlaser.homedns.org>
In reply to#20493
Am 16.02.2012 01:18, schrieb Daniel Fetchinson:
> Hi folks, often times in science one expresses a value (say
> 1.03789291) and its error (say 0.00089) in a short way by parentheses
> like so: 1.0379(9)

Just so that I understand you, the value of the last "digit" is 
somewhere between 9-9 and 9+9, right? So the value itself is rounded so 
that its last digit has the same value as the only digit to which the 
error is rounded.

> One can vary things a bit, but let's take the simplest case when we
> only keep 1 digit of the error (and round it of course) and round the
> value correspondingly.

First step is to format the values as decimal string ('{0:f}'.format). 
Then, pad both values to the same number of digits before and after the 
radix separator. Then, iterate over the strings, those digits where the 
error digits are zero are those that are taken verbatim for the value. 
The following digit is rounded and then added to the result. The 
according digit in the error is also rounded and added in brackets.

Note that you can not compute these "values", since the definition of 
the rounding depends on a decimal representation. If you have decimal 
floating point numbers, where 0.1 is representable without loss, you 
could actually do that. In order to allow common treatment as decimal as 
required for this algorithm, the first step above was the conversion to 
a decimal string.

Write tests that make sure this works, e.g. I ignored any sign and you 
also can't use str() to format the value because that could give you 
"123.45e+5" as a result.

Good luck!

Uli

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web