🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.os.linux.programowanie
Article #72446

DBL_EPSILON i Calculated Machine epsilon

#72446
From: Adam Majewski
Date: Sun, 15 Apr 2012 13:13
155 lines
4926 bytes
Witam.

Napisałem program w c ( kod poniżej). Oblicza ile potrzeba kroków ( 
iteracji tu LastIteration) aby punkt z1 uciekł z koła o promieniu ER, 
czyli sprawdza abs(z1)<ER




Program działa, ale dla n=27 wpada w nieskończoną pętlę.
Przypuszczam, że wtedy program nie rozróżnia z1 i zp :
bo wtedy distance(z1,zp)<Calculated  Machine epsilon



gdzie :
distance(z1,zp) = 1.490116e-08
Calculated  Machine epsilon = 1.19209E-07 ( używając programu z wikipedii )
http://en.wikipedia.org/wiki/Machine_epsilon
punkt jest liczbą zespoloną)
punkt zp jest punktem stałym = nie ucieka z koła o promieniu ER


Jak to się ma do :

DBL_EPSILON           = 2.220446e-16  = 
0.00000000000000022204460492503130808473 ( z float.h )
?



Pozdrawiam

Adam












============== Uruchomienie==========================

gcc -lm -Wall i.c
./a.out


=============wyniki ====================


n=  1 distance(z1,zp) = 5.000000e-01  LastIteration =        3
n=  2 distance(z1,zp) = 2.500000e-01  LastIteration =        5
n=  3 distance(z1,zp) = 1.250000e-01  LastIteration =       10
n=  4 distance(z1,zp) = 6.250000e-02  LastIteration =       19
n=  5 distance(z1,zp) = 3.125000e-02  LastIteration =       35
n=  6 distance(z1,zp) = 1.562500e-02  LastIteration =       68
n=  7 distance(z1,zp) = 7.812500e-03  LastIteration =      133
n=  8 distance(z1,zp) = 3.906250e-03  LastIteration =      261
n=  9 distance(z1,zp) = 1.953125e-03  LastIteration =      518
n= 10 distance(z1,zp) = 9.765625e-04  LastIteration =     1031
n= 11 distance(z1,zp) = 4.882812e-04  LastIteration =     2055
n= 12 distance(z1,zp) = 2.441406e-04  LastIteration =     4104
n= 13 distance(z1,zp) = 1.220703e-04  LastIteration =     8201
n= 14 distance(z1,zp) = 6.103516e-05  LastIteration =    16394
n= 15 distance(z1,zp) = 3.051758e-05  LastIteration =    32778
n= 16 distance(z1,zp) = 1.525879e-05  LastIteration =    65547
n= 17 distance(z1,zp) = 7.629395e-06  LastIteration =   131084
n= 18 distance(z1,zp) = 3.814697e-06  LastIteration =   262156
n= 19 distance(z1,zp) = 1.907349e-06  LastIteration =   524301
n= 20 distance(z1,zp) = 9.536743e-07  LastIteration =  1048590
n= 21 distance(z1,zp) = 4.768372e-07  LastIteration =  2097167
n= 22 distance(z1,zp) = 2.384186e-07  LastIteration =  4194322
n= 23 distance(z1,zp) = 1.192093e-07  LastIteration =  8388675
n= 24 distance(z1,zp) = 5.960464e-08  LastIteration = 16778821
n= 25 distance(z1,zp) = 2.980232e-08  LastIteration = 33604781
n= 26 distance(z1,zp) = 1.490116e-08  LastIteration = 68563774


=================== kod ==================


#include <stdio.h>
#include <math.h> // pow
#include <float.h> // DBL_EPSILON



double GiveLastIteration(double Zx, double Zy, double Cx, double Cy, int 
IterationMax, int ER2)
  {
   double Zx2, Zy2; /* Zx2=Zx*Zx;  Zy2=Zy*Zy  */
   double i=0.0;
   Zx2=Zx*Zx;
   Zy2=Zy*Zy;
   while  (Zx2+Zy2<ER2)  /* ER2=ER*ER */
   {
    Zy=2*Zx*Zy + Cy;
    Zx=Zx2-Zy2 + Cx;
    Zx2=Zx*Zx;
    Zy2=Zy*Zy;
    i+=1.0;
    //printf("i = %f Zx = %e = %40.38f \n", i,Zx, Zx);
   }
   return i;
  }


int main()

{
   double distance;

    int n;
    // parabolic fixed point zp = zpx = zpy*I = 0.5
    double zpx = 0.5;
    double zpy = 0.0;
// z1 = z1x + z1y*I = point of exterior of Julia set but near parabolic 
// fixed point zp
    double z1x;
    double z1y = zpy;
    double cx= 0.25;
    double cy= 0.0;
    // Escape Radius ; it defines target set  = { z: abs(z)>ER}
    // all points z in the target set are escaping to infinity
    double ER=2.0;
    double ER2;

    double LastIteration;


    //n = 1000;
    ER2= ER*ER;



    for (n =1; n<101; n++)
    {
      distance = pow(2.0,-n);
      printf("n= %d distance(z1,zp) = %e  = %40.38f ",n, distance, 
distance);
      z1x = zpx + distance;
      LastIteration = GiveLastIteration(z1x,z1y, cx,cy, n+n,ER2 );
      printf("LastIteration = %.0f \n", LastIteration);
    }

  printf("DBL_EPSILON   = %e  = %40.38f ",DBL_EPSILON , DBL_EPSILON );


   return 0;
}
Technical Details
Message-ID: <jmehj3$mkj$1@news.icm.edu.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!.POSTED!not-for-mail
From: Adam Majewski <adammaj1@o2.pl>
Newsgroups: pl.comp.os.linux.programowanie
Subject: DBL_EPSILON  i  Calculated  Machine epsilon
Date: Sun, 15 Apr 2012 15:13:51 +0200
Organization: ICM, Uniwersytet Warszawski
Lines: 155
Message-ID: <jmehj3$mkj$1@news.icm.edu.pl>
NNTP-Posting-Host: dynamic-78-8-185-96.ssp.dialog.net.pl
Mime-Version: 1.0
X-Trace: news.icm.edu.pl 1334495651 23187 78.8.185.96 (15 Apr 2012 13:14:11 GMT)
X-Complaints-To: usenet@news.icm.edu.pl
NNTP-Posting-Date: Sun, 15 Apr 2012 13:14:11 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.28) Gecko/20120313 Thunderbird/3.1.20
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit