FUNCTION
gauss
Computes the definite integral of a function using the Gauss quadrature for 3 points.
Interface
#include <codecogs/maths/calculus/quadrature/gauss.h>
using namespace Maths::Calculus::Quadrature;
This module computes the area beneath a user supplied function using an approximation given by a certain weighted sum of function values.
Consider a function and two distinct abscissas
. In order to compute an approximation of the definite integral:
(1)
we will use the Gauss-Legendre quadrature formula for 3 points:
(2)
For fixed the error of this approximation is given by
(3)
Example 1
In what follows an approximation is found for the definite integral
(4)
and the absolute error from its actual value is estimated.
#include <codecogs/maths/calculus/quadrature/gauss.h>
#include <stdio.h>
#include <math.h>
// function to integrate
double f(double x)
{
return sin(x);
}
// the primitive of f, to estimate errors
double pf(double x)
{
return -cos(x);
}
int main()
{
// compute the approximate area
double fi = Maths::Calculus::Quadrature::gauss(f, 2, 3),
// use the Leibniz-Newton formula to find a more precise estimate
realfi = pf(3) - pf(2);
// display the result and error estimate
printf(" f(x) = sin(x)\n");
printf(" I(2, 3) = %.15lf\n", fi);
printf("real value = %.15lf\n", realfi);
printf(" error = %.15lf\n\n", fabs(fi - realfi));
return 0;
}Output
f(x) = sin(x)
I(2, 3) = 0.573845954654464
real value = 0.573845660053303
error = 0.000000294601161Parameters
f
the function to integrate
a
the inferior limit of integration
b
the superior limit of integration
Returns
The definite integral of the given function from a to b.
References
Mihai Postolache - "Metode Numerice", Editura Sirius
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.