←to practical programming

Exercise "gnuplot"

Scientific plots with gnuplot.
    1. Install GSL and pyxplot and/or gnuplot and/or plotutils in your box.
      • GSL:
        sudo apt install libgsl-dev
        
      • Pyxplot:
        sudo apt install pyxplot
        
        Alternatively, you can install the latest version of Pyxplot directly from its github repository. First, install the needed libraries,
        sudo apt-get install libfftw3-dev gcc ghostscript gv imagemagick \
               libc6-dev libcfitsio-dev libgsl-dev libkpathsea-dev \
               libpng-dev libreadline-dev libxml2-dev make \
               texlive-latex-extra texlive-latex-recommended \
               texlive-fonts-extra texlive-fonts-recommended wget \
               zlib1g-dev \
        
        (perhaps all these "extra" LaTeX things (they are about a gigabyte of them) are not strictly needed.) Then install Pyxplot:
        mkdir ~/local
        cd ~/local
        git clone https://github.com/dcf21/pyxplot9.git
        cd pyxplot9
        ./configure # and install missing libraries, if anything is missing
        make -j4    # or whatever number of processors you've got
        make -j4 test
        sudo make install
        
      • Gnuplot:
        sudo apt --yes install gnuplot
        
        MacOS with homebrew:
        brew install gnuplot [--with-qt|--with-x11] [--with-cairo]
        
      • Plotutils:
        sudo apt --yes install plotutils
        
    2. Plot the error-function together with several of its tabulated values (as a test). Use i) the erf function from math.h, ii) the gsl_sf_erf function from GSL, and iii) the following approximation,
      double myerf(double x){
      /// single precision error function (Abramowitz and Stegun, from Wikipedia)
      if(x<0) return -myerf(-x);
      double a[]={0.254829592,-0.284496736,1.421413741,-1.453152027,1.061405429};
      double t=1/(1+0.3275911*x);
      double sum=t*(a[0]+t*(a[1]+t*(a[2]+t*(a[3]+t*a[4]))));/* the right thing */
      return 1-sum*exp(-x*x);
      } 
      They should produce similar curves passing through the tabulated points.
    3. Plot the gamma-function together with several of its tabulated values (factorials) as a test. Try to reproduce the plot from the Wikipedia article. Use i) the tgamma function from math.h, ii) the gsl_sf_gamma function from GSL, and iii) the following [Stirling approximation],
      double mygamma(double x){
      ///single precision gamma function (Gergo Nemes, from Wikipedia)
      if(x<0)return M_PI/sin(M_PI*x)/mygamma(1-x);
      if(x<9)return mygamma(x+1)/x;
      double lnmygamma=x*log(x+1/(12*x-1/x/10))-x+log(2*M_PI/x)/2;
      return exp(lnmygamma);
      }
  1. Do the same for the logarithm of the gamma-function.
  2. Implement the complex function complex G(complex z) that calculates Γ(z) for complex arguments (use the formula above from wikipedia, it works for complex arguments as well, I believe). Plot 3d plot of the absolute value of the Γ-function in the complex plane as in the Wikipedia article.