The following code below is from a text on numerical recipes in C++...Its purpose is to evaluate the integral of a function, "func", using the Gaussian Quadrature formula, viz:
Im trying to adapt the code to integrate my function, "func", which returns an array of values, viz:
Can anyone please show me how I may do this? I have tried a number of ways, but I keep running into errors. Thank you!
Code:
double qgaus(double func, double a, double b)
{
//elements of the integral
double xr,xm,dx,s; //s unrelated to Laplace
//at abscissas x and with weights w,
double x[] = {0.1488743389816312,0.4333953941292472,
0.6794095682990244,0.8650633666889845,0.9739065285171717};
double w[] = {0.2955242247147529,0.2692667193099963,
0.2190863625159821,0.1494513491505806,0.0666713443086881};
xm = 0.5*(b+a);
xr = 0.5*(b-a);
s = 0;
//performing the integration on func
for(int j=0;j<5;j++)
{
dx = xr*x[j];
s += w[j]*(func(xm+dx)+func(xm-dx));
}
return s *= xr;
}
Code:
void func(double *func,CKuchukDlg *pDialog)
{
enum{nSize = 100};
double Ip[nSize],p[nSize],gh[1][nSize];
double alpha[nSize],beta[nSize]; //this 's' is unrelated to Laplace's
for(int t=0;t<nSize;t++)
{
if(t==0)
{
alpha[0] = beta[0] = 1;
p[0] = sqrt(pow(alpha[0],2.0)+pow(beta[0],2.0));
homo(gh,nSize,pDialog);
Integrals(Ip,20);
func[0] = (gh[0][0] * Ip[0])/p[0];
}
else
{
alpha[t] = beta[t] = 2*t*PI;
homo(gh,nSize,pDialog);
Integrals(Ip,20);
p[t] = sqrt(pow(alpha[t],2.0)+pow(beta[t],2.0));
func[t] = (gh[0][t] * Ip[t])/p[t];
}
}
}
Can anyone please show me how I may do this? I have tried a number of ways, but I keep running into errors. Thank you!