The first answer is that using ultra-precision on fuzzy calculations is a waste of time. Approximate answers are good enough for fuzzy sets.
In your first example, the author has taken a set of evenly spaced samples and approximated the centroid of the full region with the centroid of the samples (as if the region were not distributed, but were just masses sitting at 0, 5, 10, 15, ...).
In your second example, the author has again approximated. This approximation is not very good. Note that the second example's estimate of the centroid of just the region over $[x_1,x_2]$ is as if all the mass were concentrated at $x_2$.
It is worth pointing out that both of these are approximations, both have drawbacks, and both are generally fine for getting useful results in practical systems. This does not mean that they are the best possible results.
The summation in your second example hints to the correct method. The centroid of the region bounded by $I=[x_1,x_2]$, the function $y(x)$ taking points of $I$ to real numbers, and the $x$-axis is $$\frac{\int_{x_1}^{x_2} x f(x) \mathrm{d}x}{\int_{x_1}^{x_2} f(x) \mathrm{d}x}$$.
This is overkill, especially if your functions are piecewise linear (which your output and examples are). For your output set and both examples, it would be better to follow this recipe:
- For each rectangle, replace it with a mass at its (horizontal) midpoint equal to its width times its height. (At $\frac{1}{2}x_2 + \frac{1}{2}x_3$ we have mass $(x_3-x_2)u(x_2)$. We could use $u(x_3)$ as well since they're equal.)
- For each triangle, replace it with a mass two-thirds of the way from the tip to the spine. In the second example, this would be at $\frac{2}{3}x_2 + \frac{1}{3}x_1$. The mass is one half the width ("the base") times the height.
- Decompose each trapezoid (see $[x_3,x_4]$ in the second example) into the rectangle sitting on the $x$-axis and the triangle sitting above the rectangle. Replace the pair with the mass for the triangle and the mass for the rectangle. (I.e., we get two contributions -- one for the rectangle at the midpoint and one for the triangle $2/3$ of the way along.)
Use these locations as the $x_i$ and weights as the $u(x_i)$ in either of your formulae.
This overprecise method computes the exact centroids of piece-wise linear regions.
Once more, I am sorry for my troubles. But thank you so much for your time!
– theJuls Apr 30 '14 at 16:46