ArcGamma.jpg/code: Difference between revisions
Jump to navigation
Jump to search
imported>Dmitrii Kouznetsov m (misprint in the comment) |
imported>Dmitrii Kouznetsov m (wording in comment) |
||
Line 3: | Line 3: | ||
// Copyleft 2009 by Dmitrii Kouznetsov. | // Copyleft 2009 by Dmitrii Kouznetsov. | ||
// The image and the generator can be used for free under condition that the authorship and the source are attributed. | // The image and the generator can be used for free under condition that the authorship and the source are attributed. | ||
// For the plotting, | // For the plotting, two more routines are required; | ||
// get them at [[Contour plot/Code/conto.cin]] | |||
// | // | ||
#include <math.h> | #include <math.h> |
Latest revision as of 20:49, 26 July 2009
//
// generator of picture of ArcFactorial in the complex plane. // Copyleft 2009 by Dmitrii Kouznetsov. // The image and the generator can be used for free under condition that the authorship and the source are attributed. // For the plotting, two more routines are required; // get them at Contour plot/Code/conto.cin // #include <math.h> #include <stdio.h> #include <stdlib.h> #define DB double #define DO(x,y) for(x=0;x<y;x++) using namespace std; #include <complex> typedef complex<double> z_type; #define Re(x) x.real() #define Im(x) x.imag() #define I z_type(0.,1.) z_type fracti(z_type z){ z_type s; int n; DB a[17]= {0.0833333333333333333, 0.0333333333333333333, .252380952380952381, .525606469002695418, 1.01152306812684171, 1.51747364915328740, 2.26948897420495996, 3.00991738325939817, 4.02688719234390123, 5.00276808075403005, 6.28391137081578218, 7.49591912238403393, 9.04066023436772670, 10.4893036545094823, 12.2971936103862059, 13.9828769539924302, 16.0535514167049355 }; s=a[16]/(z+19./(z+25./(z))); for(n=15;n>=0;n--) s=a[n]/(z+s); return s + log(2.*M_PI)/2. - z + (z+.5)*log(z); } // logfactorial for large values of argument except vicinity of negative part of real axis)
z_type infac0(z_type z){ z_type s; int n; DB c[28]={ 1., 0.57721566490153286061, -0.65587807152025388108, -0.042002635034095235529, 0.16653861138229148950, -0.042197734555544336748, -0.0096219715278769735621, 0.0072189432466630995424, -0.0011651675918590651121, -0.00021524167411495097282, 0.00012805028238811618615, -0.000020134854780788238656, -0.0000012504934821426706573, 0.0000011330272319816958824, -2.0563384169776071035e-7, 6.1160951044814158179e-9, 5.0020076444692229301e-9, -1.1812745704870201446e-9, 1.0434267116911005105e-10, 7.7822634399050712540e-12, -3.6968056186422057082e-12, 5.1003702874544759790e-13, -2.0583260535665067832e-14, -5.3481225394230179824e-15, 1.2267786282382607902e-15, -1.1812593016974587695e-16, 1.1866922547516003326e-18, 1.4123806553180317816e-18}; s=c[27]*z; for(n=26;n>0;n--) {s+=c[n]; s*=z;} s+=c[0]; return s;}
z_type fac0(z_type z){ return 1./infac0(z);}
z_type expaun(z_type z) {int n,m; DB x,y; x=Re(z);if(x<-.5) return expaun(z+1.)-log(z+1.); if(x>.6) return expaun(z-1.)+log(z); y=Im(z); if(fabs(y)>1.4)return expaun(z/2.)+expaun(z/2.-.5)+z*log(2.)-log(sqrt(M_PI)); return -log(infac0(z)); } z_type lof(z_type z){DB x,y; x=Re(z); y=Im(z); if(fabs(y)>5. ) return fracti(z); if(x>0 && x*x+y*y>25.) return fracti(z); return expaun(z); } // lof(z) returns 16 digits of complex logfactorial.
z_type infac1(z_type z){return infac0(z/2.)*infac0((z-1.)/2.)*sqrt(M_PI)/exp(log(2.)*z);}
z_type infac2(z_type z){return infac1(z/2.)*infac1((z-1.)/2.)*sqrt(M_PI)/exp(log(2.)*z);}
z_type infac3(z_type z){return infac2(z/2.)*infac2((z-1.)/2.)*sqrt(M_PI)/exp(log(2.)*z);}
z_type inhalf(z_type z){DB x=Re(z); DB y=Im(z); DB r=x*x+y*y; if(r<2.) return infac0(z); if(r<5.) return infac1(z); return infac2(z); }
z_type infacmi(z_type z){ if(Re(z)> 1.) return infacmi(z-1.)/z; return inhalf(z);} z_type infaclu(z_type z){ if(Re(z)<-.5) return infaclu(z+1.)*(z+1.);return inhalf(z);}
z_type infac(z_type z){DB x=Re(z),y=Im(z),t=x*x+y*y; if(t<1.)return infac0(z); if( fabs(y)> 5. || (x>0 && t>25) ) return exp(-fracti(z)); if( x>0 ) return infacmi(z); return infaclu(z);} z_type fac(z_type z){ DB x=Re(z),y=Im(z),t=x*x+y*y; if(t<2.)return 1./infac0(z); if( (x>0. && t>25.) || fabs(y)>5.) return exp(fracti(z)); if(x>0) return 1./infacmi(z); return 1./infaclu(z);} //#include "fac.cin" // Functions for Factorial'(z) z_type infp0(z_type z) { int n; z_type s; DB c[30]= {0.57721566490153286061, -1.3117561430405077622, -0.12600790510228570659, 0.66615444552916595801, -0.21098867277772168374, -0.057731829167261841373, 0.050532602726641696797, -0.0093213407348725208969, -0.0019371750670345587553, 0.0012805028238811618615, -0.00022148340258867062521, -0.000015005921785712047888, 0.000014729354015762046471, -2.8788737837686499448e-6, 9.1741426567221237268e-8, 8.0032122311507566881e-8, -2.0081667698279342458e-8, 1.8781680810439809189e-9, 1.4786300535819635383e-10, -7.3936112372844114164e-11, 1.0710777603654399556e-11, -4.5283173178463149231e-13, -1.2300681840672941359e-13, 2.9442687077718258964e-14, -2.9531482542436469238e-15, 3.0853998623541608647e-17, 3.8134277693586858102e-17, -6.4364879164190365785e-18, 4.9717783335892785568e-19, 4.0120551914810793446e-21}; s=c[29]; for(n=28;n>=0;n--){ s*=z; s+=c[n];} return s;}
z_type lofp0(z_type z){ return -infp0(z)/infac(z); } z_type facp0(z_type z){ z_type f=fac(z); f*=f; return -infp0(z)*f; } z_type lofpa(z_type z){ int n; DB q[11]; q[0] = 12.; q[1] = 5./6.; q[2] = 252./79.; q[3] = 6241./14460.; q[4 ]= 7666692./4146631.; q[5 ]= 179081182865./612465549066.; q[6 ]= 4881681043696812./3754087889491759.; q[7 ]= 86960333299682003491937./392729697097736725384440.; q[8 ]= 378191910699307315313565647105916./377413323237205130354503096392253.; q[9 ]= 696148976661357653747206985359295786942014225./ 3903889440300118372577892204070110729027524454.; q[10]= 36675782764501469367480729990524142326314524131790623634298644./ 45019657243089322180478800624616560743983830599801241354133773.; z_type c=1./(z*z), s=c/q[10]; for(n=9;n>=0;n--) s=c/(q[n]+s); return -s + .5/z + log(z);} z_type lofp2(z_type z){ return log(2.)+(lofp0(z/2.-.5)+lofp0(z/2.))/2.;} z_type lofp4(z_type z){ return log(2.)+(lofp2(z/2.-.5)+lofp2(z/2.))/2.;} z_type lofp8(z_type z){ return log(2.)+(lofp4(z/2.-.5)+lofp4(z/2.))/2.;}
z_type lofp1(z_type z){DB x=Re(z),y=Im(z), t=x*x+y*y; if(x>1) return lofp1(z-1.)+1./z; if(x<-.5) return lofp1(z+1.)-1./(z+1.); if(t<2.) return lofp0(z); return lofp4(z); }
z_type lofp(z_type z){DB x=Re(z),y=Im(z), u=y*y; if(x>=0. && (x+1.)*(x+1.)+u> 30.)return lofpa(z); if(x<=0. && (x-1.)*(x-1.)+u> 30.)return lofpa(-z)+1./z-M_PI/tan(M_PI*z); return lofp1(z);}
z_type infp(z_type z){ DB x=Re(z),y=Im(z); if(x*x+y*y<2.) return infp0(z); return -infac(z)*lofp(z);}
z_type facp(z_type z){ DB x=Re(z),y=Im(z), u=x*x+y*y; z_type c; if(u<2){c=infac0(z); return -infp0(z)/(c*c);} return fac(z)*lofp(z); //if(x>0|| fabs(y)>2.)return M_PI*insincp(M_PI*z)*infp(-z)-insinc(M_PI*z)*infp(-z); } // #include "facp.cin" z_type afacb(z_type z){ DB z0=0.461632144968362341262659542325721328468196204; DB F0=-0.12148629053584960809551455717769158215135617313; DB c2=.483836122723810585213722380854825370205628608; DB p=0.2090973242496979633924701135209125815611056; DB q=0.0565790271828431799463572817754001404669620; DB A=0.0008685913050832152753870514845664790993724; DB B=0.0002046727298252365296379380008904113017495; z_type t=(log(z)-F0)/c2; z_type v=sqrt(t); z_type u=v*(1.+v*(p+A*t)) /(1.+v*(q+B*t)) + z0; return u;} z_type afacc(z_type z){ z_type a,c,d; a=afacb(z); d=facp(a); c=z-fac(a); a+=c/d; if(abs(c)<1.e-12) return a; d=facp(a); c=z-fac(a); a+=c/d; if(abs(c)<1.e-12) return a; d=facp(a); c=z-fac(a); a+=c/d; if(abs(c)<1.e-12) return a; d=facp(a); c=z-fac(a); a+=c/d; if(abs(c)<1.e-12) return a; d=facp(a); c=z-fac(a); a+=c/d; return a; } //#include "afacc.cin" #include "conto.cin" main(){ int j,k,m,n; DB x,y, p,q, t; z_type z,c,d, cu,cd; int M=201,M1=M+1; int N=201,N1=N+1; DB X[M1],Y[N1], g[M1*N1],f[M1*N1], w[M1*N1]; // w is working array. char v[M1*N1]; // v is working array FILE *o;o=fopen("ArcFactorial.eps","w");ado(o,202,202); fprintf(o,"101 101 translate\n 10 10 scale\n"); DO(m,M1) X[m]=-10.+.1*(m-.5); DO(n,N1) Y[n]=-10.+.1*(n+.5); for(m=-8;m<9;m++) { if(m==0){M(m,-6.2)L(m,6.2)} else {M(m,-6)L(m,6)} } for(n=-6;n<7;n++) { M( -8,n)L(8,n)} fprintf(o,".006 W 0 0 0 RGB S\n"); DO(m,M1)DO(n,N1){g[m*N1+n]=9999; f[m*N1+n]=9999;} DO(m,M1){x=X[m]; //printf("%5.2f\n",x); DO(n,N1){y=Y[n]; z=z_type(x,y); c=afacc(z); // p=abs(c-d)/(abs(c)+abs(d)); p=-log(p)/log(10.)-1.; p=Re(c);q=Im(c); if(p>-999 && p<999) g[m*N1+n]=p; if(q>-999 && q<999 && fabs(q)> 1.e-14) f[m*N1+n]=q; }} fprintf(o,"1 setlinejoin 1 setlinecap\n"); p=2;q=1;
for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, (-4.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, (-3.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, (-2.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, (-1.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, ( 0.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, ( 1.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, ( 2.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,f,w,v,X,Y,M,N, ( 3.+.1*n),-q, q); fprintf(o,".01 W 0 1 0 RGB S\n");
for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, (-4.+.1*n),-q, q); fprintf(o,".01 W 1 0 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, (-3.+.1*n),-q, q); fprintf(o,".01 W 1 0 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, (-2.+.1*n),-q, q); fprintf(o,".01 W 1 0 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, (-1.+.1*n),-q, q); fprintf(o,".01 W 1 0 0 RGB S\n"); for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, ( 0.+.1*n),-q, q); fprintf(o,".01 W 0 0 1 RGB S\n"); for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, ( 1.+.1*n),-q, q); fprintf(o,".01 W 0 0 1 RGB S\n"); for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, ( 2.+.1*n),-q, q); fprintf(o,".01 W 0 0 1 RGB S\n"); for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, ( 3.+.1*n),-q, q); fprintf(o,".01 W 0 0 1 RGB S\n");
conto(o,f,w,v,X,Y,M,N, (-8. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, (-7. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, (-6. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, (-5. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, (-4. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, (-3. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, (-2. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, (-1. ),-p,p); fprintf(o,".020 W 1 0 0 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 0. ),-p,p); fprintf(o,".020 W 1 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 1. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 2. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 3. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 4. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 5. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 6. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 7. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n"); conto(o,f,w,v,X,Y,M,N, ( 8. ),-p,p); fprintf(o,".020 W 0 0 1 RGB S\n");
conto(o,g,w,v,X,Y,M,N, (-8. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, (-7. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, (-6. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, (-5. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, (-4. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, (-3. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, (-2. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, (-1. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 0. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 1. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 2. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 3. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 4. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 5. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 6. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 7. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); conto(o,g,w,v,X,Y,M,N, ( 8. ),-p,p); fprintf(o,".020 W 0 0 0 RGB S\n"); //#include"plofu.cin" M(.885,0)L(-10,0) fprintf(o,".06 W 1 1 1 RGB S\n"); M(.885,0)L(-10,0) fprintf(o,".05 W 0 0 0 RGB [.12 .12] 1 setdash S\n"); fprintf(o,"showpage\n\%\%\%Trailer"); fclose(o); // system( "gv ArcFactorial.eps &"); // for linux system( "open ArcFactorial.eps"); // for macintosh system("ps2pdf ArcFactorial.eps $"); getchar(); system("killall Preview"); //for macintosh } //end of generator of arcfactorial