Which is the machine precision of Matlab?

Hi all, I have the following problem: I want to find the argmax (not necessarily unique) of a function f(alpha,beta). Under some assumptions on f it is possible to obtain the argmax set following this procedure:
1) compute F=max f(alpha,beta) wrto alpha and beta
2) for each alpha compute H(alpha)=max f(alpha,beta) with respect to beta
3) pick alpha s.t. H(alpha)=F;
4) pick corresponding beta from step 2)
I'm trying to perform this procedure in Matlab; my question is: assuming that the maximization problems have been correctly solved, how much the result given by Matlab is precise? i.e. in step 3) I should pick alpha s.t. H(alpha)~= F+...? or I should round the numbers to which digit?
I have attached F and H(alpha).
Thank you very much!

1 Kommentar

John D'Errico
John D'Errico am 18 Feb. 2014
Bearbeitet: John D'Errico am 18 Feb. 2014
I'm intrigued here. At one point you state you know nothing of numerical analysis. At another point, you state that "under some assumptions on f, it is possible to obtain the argmax".
So which is it? You know nothing, or a fair amount?
By the way, as optimization schemes go, I'm not terribly impressed with this one.
This almost feels like your homework assignment, given the statement above, as if you were fed that line.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Iain
Iain am 18 Feb. 2014

0 Stimmen

Matlab stores and operates on doubles. Doubles have 15-ish significant figures of precision.
If you keep your numbers all roughly the same, you'll manage to get 15ish accurate digits on your answer. If you don't, then, to demonstrate try:
zero = 10^17 + 1 - 10^17
one = 10^17 - 10^17 + 1
You and I both know that the answer to both equations is 1. Double format numbers get that wrong. If you do that sum in unsigned 64 bit integers, it gets it right.
zero = uint64(10^17) + uint64(1) - uint64(10^17)
one = uint64(10^17) - uint64(10^17) + uint64(1)
unsigned 64 bit integers have a precision of "1", and a maximum value of 2^64 - 1 (approx 4*10^18), to which you may apply an offset and scaling factor

2 Kommentare

MRC
MRC am 18 Feb. 2014
Thank you very much Iain, just to be sure:
(1) " _If you keep your numbers all roughly the same, you'll manage to get 15ish accurate digits on your answer. If you don't, then, ... "_you mean that if from the very first step of my code I round all results, say,to 17 digits after the decimal point, then my final result will be accurate until the 15th digit after the decimal point?
(2) How can I say to Matlab to " keep numbers all roughly the same "? Does Matlab do it by default?
Thanks!
Iain
Iain am 18 Feb. 2014
1) No. I mean that matlab rounds every double format number to the nearest number it can represent. This allows 15ish significant figures, significant figures are NOT decimal places. 156965468456231 has 15 significant figures, just like 0.000156965468456231 has 15 significant figures.
2) Matlab does not do that automatically. You need to understand your scenario well to establish where your numerical issues will occur.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 18 Feb. 2014
Bearbeitet: dpb am 18 Feb. 2014

0 Stimmen

Default in Matlab is double which is stored with 53 bits of precision. This converts to roughly 15-16 decimal digits of precision (log10(2^53)-->15.95).

5 Kommentare

Walter Roberson
Walter Roberson am 18 Feb. 2014
Notice that you still need to do standard numeric analysis to determine how much precision is carried around at each step. http://en.wikipedia.org/wiki/Propagation_of_uncertainty
MRC
MRC am 18 Feb. 2014
Do you mean that I cannot just round the decimal digits of F and H(alpha) at 15-16?
MRC
MRC am 18 Feb. 2014
I have never done numerical analysis: do you know whether there is a simpler way to solve the problem? Thanks
John D'Errico
John D'Errico am 18 Feb. 2014
I think dpb was asleep here. A double is stored with 53 BITS of precision, not 53 DIGITS as was stated at one point.
dpb
dpb am 18 Feb. 2014
Ooops...typo indeed, edited/corrected. Thanks for pointing it out...

Melden Sie sich an, um zu kommentieren.

Gefragt:

MRC
am 17 Feb. 2014

Bearbeitet:

am 18 Feb. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by