Machine Epsilon in MATLAB

3
2/4/2014 Machine epsilon in MATLAB http://www.physicsforums.com/showthread.php?t=590481 1/3 User Name •••••••• Auto-Login Log in Gengar #1 Mar26-12, 12:26 PM Antiphon #2 Mar26-12, 06:57 PM AlephZero #3 Mar26-12, 07:54 PM Physics Forums > Other Sciences > Computing & Technology > Programming & Computer Science Machine epsilon in MATLAB by Gengar Tags: epsilon, machine, matlab P: 13 Simple enough - I'm just trying to find the smallest positive real number, ε, such that 1 + ε ≠ 1 in MATLAB (double precision). So the value 'eps' in MATLAB is actually not quite defined this way, and using this program min = 0; max = 1; test = 1; while test~=(min+max)/2 test = (min+max)/2; if 1+test~=1 max=test; end if 1+test==1 min=test; end end yields the value 1.1102x10^(-16), which does satisfy 1+ε ≠1. This value is very close to eps/2, but is not eps/2 (they differ by 2x10^(-32)). And 1+eps/2=1 anyway so that seemingly can't be right. My question is this - is there a published value for MATLAB's machine epsilon, or is my value correct? My value seems quite annoying in that it feels like it should be eps/2, and in my assignment it referenced eps/2 as the machine epsilon. Cheers! Science news on Phys.org A breath of Beijing air gets metagenomics treatment Ads out to know us in mobile Internet Age Facebook battles to stay young and cool P: 1,781 Matlab uses the native floating point instructions of the processor it's running on. Epsilon will depend on the machine. The matlab value might be the largest one of all the supported platforms. Engineering Sci A dvisor P: 5,795 Quote by Gengar Simple enough - I'm just trying to find the smallest positive real number, ε, such that 1 + ε ≠ 1 in MATLAB (double REGISTER GET POSTS LIBRARY BLOGS S S S S S S M

description

ghghg

Transcript of Machine Epsilon in MATLAB

  • 2/4/2014 Machine epsilon in MATLAB

    http://www.physicsforums.com/showthread.php?t=590481 1/3

    User Name Auto-Login Log in

    Gengar #1Mar26-12, 12:26 PM

    Antiphon #2Mar26-12, 06:57 PM

    AlephZero #3Mar26-12, 07:54 PM

    Physics Forums > Other Sciences > Computing & Technology > Programming & Computer Science

    Machine epsilon in MATLABby Gengar Tags: epsilon, machine, matlab

    P: 13 Simple enough - I'm just trying to find the smallest positive realnumber, , such that 1 + 1 in MATLAB (double precision). Sothe value 'eps' in MATLAB is actually not quite defined this way,and using this program

    min = 0;max = 1;

    test = 1;

    while test~=(min+max)/2 test = (min+max)/2; if 1+test~=1 max=test; end if 1+test==1 min=test; endend

    yields the value 1.1102x10^(-16), which does satisfy 1+ 1. This value is very close to eps/2, but is not eps/2(they differ by 2x10^(-32)). And 1+eps/2=1 anyway so that seemingly can't be right. My question is this - isthere a published value for MATLAB's machine epsilon, or is my value correct? My value seems quite annoying inthat it feels like it should be eps/2, and in my assignment it referenced eps/2 as the machine epsilon. Cheers!

    Science news on Phys.org A breath of Beijing air gets metagenomics treatment Ads out to know us in mobile Internet Age Facebook battles to stay young and cool

    P: 1,781 Matlab uses the native floating point instructions of the processor it's running on. Epsilon will depend on the machine. Thematlab value might be the largest one of all the supported platforms.

    Engineering

    Sci Advisor

    P: 5,795

    Quote by Gengar

    Simple enough - I'm just trying to find the smallest positive real number, , such that 1 + 1 in MATLAB (double

    REGISTER GET POSTS LIBRARY BLOGS

    ShareShareShareShareShareShareMore

  • 2/4/2014 Machine epsilon in MATLAB

    http://www.physicsforums.com/showthread.php?t=590481 2/3

    jhae2.718 #4Mar26-12, 07:58 PM

    Gengar #5Mar27-12, 05:27 AM

    P: 5,795 Simple enough - I'm just trying to find the smallest positive real number, , such that 1 + 1 in MATLAB (doubleprecision).

    That is not a good definition. You really want the smallest number such that (a) + (a) a for any value of a. Actually that'snot a complete definition either, since you also need to consider multiplication and division, not just addition and subtraction.

    For a computer CPU with IEEE 64 bit floating point arithmetic, the value of is 2-52 = approximately 2.2044e-16. Your code isprobably calculating the floating point number that is closest to, but not equal to, /2 (which is where your difference of10^-32 is coming from).

    A simple algorithm (in C) is

    int diff(double a, double b){ return (a != b);}

    double eps = 1.0;while (diff(1.0 + eps, 1.0)) eps /= 2;eps *= 2;

    Using a separate function to compare the numbers defeats optimizng compilers that figure out (wrongly!) that testing 1+epsagainst 1 is the same as testing whether eps is zero.

    PF Gold

    P: 1,142

    Machine epsilon in MATLAB

    In MATLAB, eps is a function that returns machine epsilon. For me it is 2.2204e-16.

    If you run edit eps you get:

    %EPS Spacing of floating point numbers.% D = EPS(X), is the positive distance from ABS(X) to the next larger in% magnitude floating point number of the same precision as X.% X may be either double precision or single precision.% For all X, EPS(X) is equal to EPS(ABS(X)).%% EPS, with no arguments, is the distance from 1.0 to the next larger double% precision number, that is EPS with no arguments returns 2^(-52).%% EPS('double') is the same as EPS, or EPS(1.0).% EPS('single') is the same as EPS(single(1.0)), or single(2^-23).%% Except for numbers whose absolute value is smaller than REALMIN,% if 2^E

  • 2/4/2014 Machine epsilon in MATLAB

    http://www.physicsforums.com/showthread.php?t=590481 3/3

    AlephZero #6Mar27-12, 10:11 AM

    For a computer CPU with IEEE 64 bit floating point arithmetic, the value of is 2-52 = approximately 2.2044e-16. Yourcode is probably calculating the floating point number that is closest to, but not equal to, /2 (which is where yourdifference of 10^-32 is coming from).

    Would it be wrong to factorise a + a = (1+)a? In which case the problem is unchanged - and for this task I don't need totake multiplication/division into account. If my factorisation is incorrect, then what would be the smallest value, , be such

    that (a) + (a) a for any a? It is not eps=2.2044e-16, as my value still satisfies the above condition. Interestingly, eps/2does satisfy the condition for a > 2 (integer-wise) but not for a=1 or a=2.

    Engineering

    Sci Advisor

    P: 5,795

    Quote by Gengar

    Would it be wrong to factorise a + a = (1+)a?

    That is wrong, unless you can prove they are equal for the computer arithmetic you are using. Unlike mathematics, in generalcomputer arithmetic is not commutative or associative.

    For example if the value of a is close to zero, a may be too small to represent as a number different from 0, even if was anumber as "big" as 0.1. In that case computing a + a would give a, but computing (1+)a would give a different result.

    Register to reply

    Related Discussions

    Show |x-a|< epsilon IFF a-epsilon < x < a+epsilon Calculus & Beyond Homework 3

    Machine epsilon to verify precision Math & Science Software 0

    Material in machine tool body (milling machine) Materials & Chemical Engineering 0

    determine the machine precision in Matlab Math & Science Software 3

    TERMS OF SERVICE PRIVACY CONTACT US PARTNERS TOP

    Copyright 2014 Physics Forums | Copyright 2014, vBulletin Solutions, Inc.