Re: numerical analysis (composite numerical integration)
- From: "user923005" <dcorbit@xxxxxxxxx>
- Date: 3 Jan 2007 02:08:45 -0800
I am horrified at my old trapezoidal rule. It had redundant
calculations of f(). This is how it should have been done:
double trapezoidal_rule(double a, double b, int n, double (*f)(double))
{
double area = 0;
double h = (b - a) / n;
unsigned i;
area = f(a);
for (i = 1; i < n; i++) {
area += f(a + i * h) * 2.0;
}
area += f(b);
area *= h * 0.5;
return area;
}
.
- Follow-Ups:
- Re: numerical analysis (composite numerical integration)
- From: Carl Barron
- Re: numerical analysis (composite numerical integration)
- From: user923005
- Re: numerical analysis (composite numerical integration)
- Prev by Date: Re: Looking for suggestions on a root search strategy
- Next by Date: Re: numerical analysis (composite numerical integration)
- Previous by thread: Looking for suggestions on a root search strategy
- Next by thread: Re: numerical analysis (composite numerical integration)
- Index(es):