Calculate the variance of a distribution analytically I want to calculate the variance of a certain distribution.
I have a rectangle that is getting shifted to the right (i.e. shear transformation). To obtain the distribution I am computing the value of each column. Here is an example of the original data (Left) and its distribution (Right).
This the original data.

and this is its distribution, which was produced by just counting the columns values.

The idea is that I want to compute the variance ($\sigma^{2}$) of each of these distributions from 1 $\rightarrow 10$ and obtain the variance curve, that shows how the variance change with different shear transformations.
The current variance curve of these distribution looks like this:

it is 0 at step 0 because the distribution is flat, then it increases until a certain point before it decreases back again.
What I did so far is use simulated data of a rectangle under a shear transformation and compute the variance of the distribution. Now I would like to come up with an analytical solution (using a formula) to get the variance curve. Therefore I considered the following calculation for the distribution at $2$:

Where $h(x)$ (probability density function) is the following:
$$h(x)\begin{matrix}
ax \cdots \cdots \cdots \cdots  0\lt x\lt x_{1} \\c\cdots \cdots \cdots \cdots x_{1}\lt x\lt x_{2}
 \\-x+w\cdots \cdots \cdots x_{2}\lt x\lt x_{3} \\
0\cdots \cdots \cdots otherwise
\end{matrix}$$
In this case, my continuous random variables is $P(x)$ is uniform $\in [0,x_{3}]$, which is the column values.
Taking all of this into account I compute the variance:
$$var(h(x))=E[h(x^{2})]-E[h(x)]^{2}$$
$$var(h(x))=\int_{0}^{x_{3}}h(x)^{2}P(x)dx-[h(x)P(x)]^{2}dx$$
$$var(h(x))=\int_{0}^{x_{1}}h(x)^{2}P(x)dx+\int_{x_{1}}^{x_{2}}h(x)^{2}P(x)dx+\int_{x_{2}}^{x_{3}}h(x)^{2}P(x)dx - [\int_{0}^{x_{1}}h(x)P(x)dx+\int_{x_{1}}^{x_{2}}h(x)P(x)dx+\int_{x_{2}}^{x_{3}}h(x)P(x)dx]^{2}$$
My question is, how to proceed from the last equation and get the final numeric value of the variance? and can this be translated for the rest of the distributions? if so, how?

I think your h(x) is a so called mixture distribution. In your example, there are actually three distributions of h(x), either h1(x)=ax, h2(x)=c, or h3(x)=-x+w, with h1(x) and h3(x) both being uniform, and h2(x) being a point-mass. And these three are mixed with particular weights w, resulting in the total distribution of h(x). So this page will be helpful:
https://en.wikipedia.org/wiki/Mixture_distribution
Look at the paragraph "Moments" where the variance formula is given.
B.t.w. as I understand it now, your "distribution" graphs are somewhat confusing, as they do not show the distribution of h(x), but rather the relation between x (which I guess is uniformly distributed) and h(x).
Regards, Ben.
