Let's look at the trapezoid rule in its simplest form, where there is only ONE interval:

$\displaystyle \int_a^bf(x)\ dx \approx (b - a) * \dfrac{f(a) + f(b)}{2}.$

If f(a) = 0 this reduces to $(b - a) * \dfrac{0 + f(b)}{2} = \dfrac{1}{2} * (b - a) * f(b)$, which is indeed the area of a triangle.

Now you are using more than one interval for your approximation, but the same logic will apply to subintervals. So for any subinterval where either

f(a) or f(b) = 0, the associated trapezoid degenerates into a triangle. You did not make a mistake; you discovered something you did not expect. Good job.

The midpoint formula does have a similarity to the trapezoid rule, but it calls for evaluating the function at only one point in the sub-interval, not two. Again, this is easiest to see if we put each rule into its simplest form, where there is only ONE interval.

$\displaystyle \int_a^bf(x)\ dx \approx (b - a) * \dfrac{f(a) + f(b)}{2}.$ Trapezoid

$\displaystyle \int_a^bf(x)\ dx \approx (b - a) * f\left(\dfrac{a + b}{2}\right).$ Midpoint

In the trapezoid rule we average the values of the function at the endpoints; in the midpoint rule we value the function of the average of the endpoints.

Does this help?