17.11.2012 Views

Numerical recipes

Numerical recipes

Numerical recipes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

152 Chapter 4. Integration of Functions<br />

#include <br />

#define EPS 3.0e-11 EPS is the relative precision.<br />

void gauleg(float x1, float x2, float x[], float w[], int n)<br />

Given the lower and upper limits of integration x1 and x2, andgivenn, this routine returns<br />

arrays x[1..n] and w[1..n] of length n, containing the abscissas and weights of the Gauss-<br />

Legendre n-point quadrature formula.<br />

{<br />

int m,j,i;<br />

double z1,z,xm,xl,pp,p3,p2,p1; High precision is a good idea for this routine.<br />

m=(n+1)/2; The roots are symmetric in the interval, so<br />

xm=0.5*(x2+x1);<br />

we only have to find half of them.<br />

xl=0.5*(x2-x1);<br />

for (i=1;i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!