home *** CD-ROM | disk | FTP | other *** search
- x-gateway: rodan.UU.NET from info-gnuplot to comp.graphics.gnuplot; Fri, 6 Nov 1992 11:46:24 EST
- Message-ID: <199211061349.AA24351@ames.arc.nasa.gov>
- Date: Fri, 06 Nov 1992 17:38:00 +0100
- From: "MSFD1::MOEHRING" <moehring@msfd1.dnet.gwdg.de>
- Newsgroups: comp.graphics.gnuplot
- Path: sparky!uunet!wendy-fate.uu.net!info-gnuplot
- Sender: info-gnuplot-request@arc.nasa.gov
- Subject: (no subject given!)
- Lines: 61
-
- I have here the version 3.2 of theGNUPLOT program and use it on an MSDOS
- computer. I think that the calculation of the complex gamma function is
- not too difficult and can easily be included in GNUPLOT. Here is a routine
- to compute the gamma-function for complex arguments which is suitable for
- inclusion in GNUPLOT.
-
-
- /* This approximation is based on Stirlings formula, see e.g.
- M. Abramowitz, I.A. Stegun, Handbook of mathematical functions */
-
- f_gamma()
- {
- struct value a;
- static double sti[]={1./12,-1./360,1./1260,-1./1680,5/(66.*90),
- -691/(132.*2730),7/(6.*182)};
- double xr,xi,gr,gi,z1,z2,z3,z4,z5,z6,z7;
- int n,i;
- char spiegel;
- (void)pop(&a);xr=real(&a);xi=imag(&a);
- spiegel=1;n=0;
- if(xr<0) xr=1-xr; else spiegel=0;
- z1=196-14*xi;
- if((xr-1)*(xr-1)<z1) n=(int)(sqrt(z1)-xr)+2;
- xr+=n;
- if(xr<1) {n=1;xr++;}
- z3=xr*xr+xi*xi;z4=0.5*log(z3);z5=atan(xi/xr);
- gr=(xr-0.5)*z4-xi*z5-xr+0.5*log(2*Pi);
- gi=(xr-0.5)*z5+xi*z4-xi;
- z4=-xi/z3;z3=xr/z3;
- z1=z3*z3-z4*z4;z2=2*z3*z4;
- z5=sti[6];z6=0;
- for(i=5;i>=0;i--)
- {z7=z5*z1-z6*z2;z6=z5*z2+z6*z1;z5=z7+sti[i];}
- gr += z5*z3 - z6*z4;gi+=z5*z4+z6*z3;
- if (gr>88){undefined = TRUE;z5=gr;} else z5=exp(gr);
- gr=z5*cos(gi);gi=z5*sin(gi);
- if(n>0)
- { z1=xr-1;z2=xi;
- for(i=2;i<=n;i++)
- {z3=z1*(xr-i)-z2*xi;z2=z1*xi+z2*(xr-i);z1=z3;}
- z3=z1*z1+z2*z2;z4=(gr*z1+gi*z2)/z3;
- gi=(gi*z1-gr*z2)/z3;gr=z4;
- }
- if(spiegel)
- {z3=exp(-Pi*xi);
- z1=0.5*sin(Pi*(xr-n))*(z3+1/z3);z2=-0.5*cos(Pi*(xr-n))*(z3-1/z3);
- z3=z1*gr-z2*gi;z2=z1*gi+z2*gr;z1=z3;
- if(z3==0.0){undefined = TRUE; z3=1.;} else z3=z1*z1+z2*z2;
- gr=Pi*z1/z3;gi=Pi*z2/z3;
- }
- push( complex(&a,gr,gi));
- }
-
- To include this routine in the GNUPLOT program, I have modified the files
- "STANDARD.C" and "PLOT.H". In "STANDARD.C" I have removed all the stuff
- about the gamma-function and replaced it by the above function. Then I have
- defined GAMMA in "PLOT.H" by:
-
- #define GAMMA gamma
-
- Then it works fine after compilation with Turbo C.
-