Forgotten Password?

Or login with:

• http://facebook.com/
• https://www.google.com/accounts/o8/id
• https://me.yahoo.com
COST (GBP)
1.00
0.00
0

gauss

Computes the definite integral of a function using the Gauss quadrature for 3 points.
Controller: CodeCogs
Contents

C++

Gauss

 doublegauss( double (*f)(double)[function pointer] double a double b )[inline]
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 $\inline&space;f:I&space;\subset&space;\mathbb{R}&space;\rightarrow&space;\mathbb{R}$ and two distinct abscissas $\inline&space;a&space;<&space;b&space;\in&space;I$. In order to compute an approximation of the definite integral:
$I&space;=&space;\int_a^b&space;f(x)&space;\mathrm{d}x$
we will use the Gauss-Legendre quadrature formula for 3 points:

$I&space;\approx&space;\frac{b-a}{18}&space;\left[5f\left(\frac{b+a}{2}&space;+&space;\frac{a-b}{2}\sqrt{\frac{3}{5}}\right)&space;+&space;8f\left(\frac{b+a}{2}\right)&space;+&space;5f\left(\frac{b+a}{2}&space;+&space;\frac{b-a}{2}\sqrt{\frac{3}{5}}\right)\right].$

For fixed $\inline&space;\displaystyle&space;\xi&space;\in&space;(a,&space;b)$ the error of this approximation is given by
$\epsilon&space;=&space;\frac{(b-a)^7}{31500}&space;\frac{d^6}{dx^6}&space;f(\xi).$

Example 1

In what follows an approximation is found for the definite integral
$\int_2^3&space;\sin&space;x&space;\,dx$
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.000000294601161

References

Mihai Postolache - "Metode Numerice", Editura Sirius

Parameters

 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.

Authors

Lucian Bentea (September 2006)
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2022-03-15 01:04:17