|
I am trying to integrate a math function 'func' which will be entered(typed) by the user, but I cannot figure out how to convert the string to a function which would be called by the integtal function.
double integral(double xLeft, double xRight, double func(double), int nDivs) { int i; double area = 0.0;
double deltaX = (xRight - xLeft)/nDivs;
double midpointX;
midpointX = xLeft + deltaX/2.0;
for (i = 0; i < nDivs; i++) { area += func(midpointX) * deltaX;
midpointX += deltaX;
}
return area; }
Thanks for any help
Electronics and Computer Hobbyist |