Tetration/Code/TailorExpansion3ipower25

From Citizendium
Jump to navigation Jump to search

//

TetrationTailorExpansion3ipower25.jpg
// code TetrationTailorExpansion3ipower25.cc generating the plot
// of the sum of the first 50 terms of the Taylor series for tetration developed at 3i.
// Source: http://en.citizendium.org/wiki?title=TetrationTailorExpansion3ipower25.jpg/code
// Copyleft 2008-2009 by Dmitrii Kouznetsov 
//In order to generate the figure above, you need the plotter routines
// ContourPlot/code/ado.cin , than makes the header of the eps file, and
// ContourPlot/code/conto.cin, that draws there the contour lines.
// With these routines, you may compile and execute the source below

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
#include <complex.h>
#define z_type complex<double>
#define Re(x) x.real()
#define Im(x) x.imag()
#define I z_type(0.,1.)
z_type tai3(z_type z)
{ int K=50,k;   // change for 25 to work with 25 terms
 z_type DER3[51]={
 z_type( 0.37090658903228507226, 1.33682167078891400713)
,z_type( 0.03660096537598455518, 0.13922215389950498565)
,z_type(-0.16888431840641535131, 0.09718533619629270148)
,z_type(-0.12681315048680869007,-0.11831628767028627702)
,z_type( 0.04235809310323926380,-0.10520930088320722129)
,z_type( 0.05848306393563178218,-0.00810224524496080435)
,z_type( 0.02340031665294847393, 0.01807777011820375229)
,z_type( 0.00344260984701375092, 0.01815103755635914459)
,z_type(-0.00803695814441672193, 0.00917428467034995393)
,z_type(-0.00704695528168774229,-0.00093958506727472686)
,z_type(-0.00184617963095305509,-0.00322342583181676459)
,z_type( 0.00054064885443097391,-0.00189672061015605498)
,z_type( 0.00102243648088806748,-0.00055968657179243165)
,z_type( 0.00064714396398048754, 0.00025980661935827123)
,z_type( 0.00010444455593372213, 0.00037199472598828116)
,z_type(-0.00011178535404343476, 0.00016786687552190863)
,z_type(-0.00010630158710808594, 0.00002072200033125881)
,z_type(-0.00005078098819110608,-0.00003575913005741248)
,z_type(-0.00000314742998690270,-0.00003523185937587781)
,z_type( 0.00001347661344130504,-0.00001333034137448205)
,z_type( 0.00000980239082395275, 0.00000047607184151673)
,z_type( 0.00000355493475454698, 0.00000389816212201278)
,z_type(-0.00000021552652645735, 0.00000296273413237997)
,z_type(-0.00000131673903627820, 0.00000097381354534333)
,z_type(-0.00000083401960806066,-0.00000018663858711081)
,z_type(-0.00000022869610981361,-0.00000037497716770031)
,z_type( 0.00000005372584613379,-0.00000023060136585176)
,z_type( 0.00000011406656653786,-0.00000006569510293486)
,z_type( 0.00000006663595460757, 0.00000002326630571343)
,z_type( 0.00000001396786846375, 0.00000003315118300198)
,z_type(-0.00000000684890556421, 0.00000001713041981611)
,z_type(-0.00000000916619598268, 0.00000000403886083652)
,z_type(-0.00000000502933384276,-0.00000000222121299478)
,z_type(-0.00000000084484352792,-0.00000000273668661113)
,z_type( 0.00000000070086729861,-0.00000000124687683156)
,z_type( 0.00000000070558101710,-0.00000000021962577544)
,z_type( 0.00000000035900951951, 0.00000000018774741308)
,z_type( 0.00000000005248658571, 0.00000000021201177126)
,z_type(-0.00000000006264758835, 0.00000000009059171879)
,z_type(-0.00000000005333473585, 0.00000000001006078866)
,z_type(-0.00000000002432138144,-0.00000000001506937008)
,z_type(-0.00000000000331880379,-0.00000000001544700067)
,z_type( 0.00000000000501652570,-0.00000000000658967459)
,z_type( 0.00000000000401214135,-0.00000000000036708383)
,z_type( 0.00000000000158629111, 0.00000000000119885992)
,z_type( 0.00000000000019668766, 0.00000000000106532662)
,z_type(-0.00000000000036355730, 0.00000000000047229527)
,z_type(-0.00000000000029920206, 0.00000000000001251827)
,z_type(-0.00000000000010305550,-0.00000000000009571381)
,z_type(-0.00000000000000910369,-0.00000000000007087680)
,z_type( 0.00000000000002418310,-0.00000000000003240337)
};
z_type s=0.,t=1.;
 z-=z_type(0.,3.); z/=2.; 
for(k=0;k<K;k++) { s+=DER3[k]*t; t*=z; }
return s;
}
#include "conto.cin"
main(){ int j,k,m,n; DB x,y, p,q, t; z_type z,c,d, cu,cd;
z_type Zo=z_type(.31813150520476413, 1.3372357014306895);
z_type Zc=z_type(.31813150520476413,-1.3372357014306895);
 int M=403,M1=M+1;
 int N=402,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("TetrationTailorExpansion3ipower25.eps","w");ado(o,0,0,82,82);
fprintf(o,"41 11 translate\n 10 10 scale\n");
DO(m,M1) X[m]=-4.+.02*(m-1.5);
DO(n,N1) Y[n]=-1. +.02*(n-1.5);
for(m=-4;m<5;m++) {	if(m==0){M(m,-1.1)L(m,6.1)}
			else	{M(m,-1)L(m,6)}			}
for(n=-1;n<7;n++) {M(  -4,n)L(4,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;	}
for(m=0;m<M1;m++){x=X[m]; //printf("run at x=%6.3f\n",x);
		DO(n,N1){y=Y[n]; z=z_type(x,y);
				c=tai3(z);
				p=Re(c);  q=Im(c);
				if(p>-999 && p<999) g[m*N1+n]=p;
				if(q>-999 && q<999) f[m*N1+n]=q;
			}}
p=1;q=.5;
                conto(o,g,w,v,X,Y,M,N, ( Re(Zo) ),-q,q); fprintf(o,".03 W 1  .6 1 RGB  [.07 .07] 1 setdash S\n");
                conto(o,f,w,v,X,Y,M,N, ( Im(Zo) ),-q,q); fprintf(o,".03 W .5 1 .5 RGB  [.07 .07] 1 setdash S\n");
                conto(o,f,w,v,X,Y,M,N, (-Im(Zo) ),-q,q); fprintf(o,".03 W .5 1 .5 RGB  [.07 .07] 1 setdash S\n");
                                                                     fprintf(o,"[1 0] 0 setdash 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,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");
                  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,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");
//M(-10,0)L(-2,0)fprintf(o,".04 W 0 0 0 RGB [.1 .1] 0 setdash  S\n");
fprintf(o,"showpage\n\%\%\%Trailer"); fclose(o);
//system( "ggv TetrationTailorExpansion3ipower25.eps"); //for linux
system(  "open TetrationTailorExpansion3ipower25.eps"); //for macintosh
system("ps2pdf TetrationTailorExpansion3ipower25.eps"); //for pdflatex
getchar(); system("killall Preview");			//for macintosh
printf("The code from http://en.citizendium.org/wiki/Image:TetrationTailorExpansion3ipower25.jpg/code\n");
}

//end of code TetrationTailorExpansion3ipower25.cc by Dmitrii Kouznetsov