• Create Account

### #Actualhaegarr

Posted 28 December 2012 - 02:48 AM

To my knowledge, the midpoint integration sums up rectangles with a width equal to your stepSize (assuming homogeneous sampling) and a height equal to the function value in the middle between the 2 samples. Your code snippet, however, doesn't sum up rectangles but irregular trapezoids by splitting each interval into half and fitting a trapezoid to each of them.

I'd say that
for(int I = 0; I < steps; I++) {
ymid = F(xn+stepSize*0.5f);
integral += ymid*stepSize;
xn += stepSize;
}
is all what's needed for the midpoint method integration. But perhaps this is just a naming confusion!?

### #2haegarr

Posted 28 December 2012 - 02:47 AM

To my knowledge, the midpoint integration sums up rectangles with a width equal to your stepSize (assuming homogeneous sampling) and a height equal to the function value in the middle between the 2 samples. Your code snippet, however, doesn't sum up rectangles but irregular trapezoids by splitting each interval into half and fitting a trapezoid to each of them.

I'd say that
for(int I = 0; I < steps; I++) {    ymid = F(xn+stepSize*0.5f);    integral += ymid*stepSize;    xn += stepSize;}
is all what's needed for the midpoint method integration. But perhaps this is just a naming confusion!?

### #1haegarr

Posted 28 December 2012 - 02:46 AM

To my knowledge, the midpoint integration sums up rectangles with a width equal to your stepSize (assuming homogeneous sampling) and a height equal to the function value in the middle between the 2 samples. Your code snippet, however, doesn't sum up rectangles but irregular trapezoids by splitting each interval into half and fitting a trapezoid to each of them.

I'd say that

for(int I = 0; I < steps; I++) {
ymid = F(xn+stepSize*0.5f);
integral += ymid*stepSize;
xn += stepSize;
}

is all what's needed for the midpoint method integration.

PARTNERS