Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Retaining precision after subtraction

Subject: Retaining precision after subtraction

From: kevbrick Brick

Date: 27 Apr, 2010 20:52:04

Message: 1 of 4

I've a simple question:

I have a script that calculates a p-value, which is often a tiny number (i.e. 1e-80). I need the script to return the 1-p value but retain the precision. When I try to do this, matlab always returns 1 for p-values below 1e-15. Can anyone tell me how to retain the precision of the calculation ?

Thanks in advance

Subject: Retaining precision after subtraction

From: Bruno Luong

Date: 27 Apr, 2010 21:29:05

Message: 2 of 4

"kevbrick Brick" <kevbric.k+spam@gmail.com> wrote in message <hr7ipk$kbg$1@fred.mathworks.com>...
> I've a simple question:
>
> I have a script that calculates a p-value, which is often a tiny number (i.e. 1e-80). I need the script to return the 1-p value but retain the precision. When I try to do this, matlab always returns 1 for p-values below 1e-15. Can anyone tell me how to retain the precision of the calculation ?

help EPS

After you'll know why what you ask is not possible, unless you perform symbolic calculation.

Bruno

Subject: Retaining precision after subtraction

From: Roger Stafford

Date: 27 Apr, 2010 21:31:04

Message: 3 of 4

"kevbrick Brick" <kevbric.k+spam@gmail.com> wrote in message <hr7ipk$kbg$1@fred.mathworks.com>...
> I've a simple question:
>
> I have a script that calculates a p-value, which is often a tiny number (i.e. 1e-80). I need the script to return the 1-p value but retain the precision. When I try to do this, matlab always returns 1 for p-values below 1e-15. Can anyone tell me how to retain the precision of the calculation ?
>
> Thanks in advance
-----------
  It is inherent in double precision floating point numbers that subtracting a number less than 2^(-54) (which is about 5.55e-17) from 1 will not change the 1. Even with substantially larger numbers there would be a heavy loss of precision in such a subtraction. You cannot have it otherwise if you use 'double' numbers. You will have to make some alteration in your script to return just the p-value without subtracting it from 1 and alter your program that receives it accordingly.

  The only alternative would be to deal with symbolic quantities that are capable of much higher accuracy perhaps using the 'vpa' facility.

Roger Stafford

Subject: Retaining precision after subtraction

From: dpb

Date: 27 Apr, 2010 23:24:18

Message: 4 of 4

kevbrick Brick wrote:
> I've a simple question:
>
> I have a script that calculates a p-value, which is often a tiny number
> (i.e. 1e-80). I need the script to return the 1-p value but retain the
> precision. When I try to do this, matlab always returns 1 for p-values
> below 1e-15. Can anyone tell me how to retain the precision of the
> calculation ?

Besides the other response, I'd suspect that a probability estimate of
1E-80 is probably meaningless, anyway.

But, you could in the case in point generate the text result pretty
easily since it's the number of 9's of the exponent followed by the
remainder from 1.0 of p*1E(exp). (Not that I think printing that out
will do anybody any good... :) )

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us