The integral in centre of mass (one dimension) This is the integral for finding  the centre of mass in one dimension:
$$X=\frac{1}{M}\int xdm.\tag{1}$$
But I was wondering whether we could do it by taking x as the integrating variable:
A homogenous rod of length $X$ is split into $N$ regions of width $\Delta x$.
Let $m$ be the mass of every such region.
As $N\rightarrow \infty$, $\Delta x \rightarrow dx.$
$$\text{Centre of mass}=\frac{\int mdx}{\int m}=\frac{m}{M}\int_0^xdx=\frac{mX}{2M},\tag{2}$$
where $M=\text{total mass}$ and $m=\text{some constant}.$
But it is known that
$$\text{Centre of mass}=\frac{X}{2},\tag{3}$$
$$\therefore \frac{mX}{2M}=\frac{X}{2}\tag{4},$$
$$\therefore m=M\tag{5}.$$
It is faulty ($m$ is not equal to $M$). Where have I gone wrong?
Is it possible to express the integral (in centre of mass in one dimension expression) by having $x$ as the integrating variable (like I attempted to do in the picture)? If not, then why?
 A: Your equation (2) is wrong. To use $x$ as the integrating variable you need to change $x\,dm$ into $x\,\dfrac{dm}{dx}\,dx$. This means we need to define $m$ as a function of $x$, and the most reasonable way to do that while keeping the original meaning of $dm$ is to let $m(x)$ be the mass of the section that goes from $0$ to $x$.
A: The integral for the center of mass, using your notation, is correct:$$ \text{CM}=\frac{1}{M} \int_{a}^{b} xdm$$
Notice that $mdx \neq xdm$ in your equation 2. Thus, you are no longer calculating the center of mass.
An easier way to think about this is defining a "linear mass density variable" $\lambda$, which is given by $$\lambda = \frac{M}{X}$$ since the rod is homogenous.
Then, in order to integrate using $dx$, you could note that $dm = \lambda dx$.
Thus, your integral for the center of mass becomes: $$\text{CM}=\frac{1}{M} \int_{a}^{b} xdm = \frac{1}{M}\int_{0}^{X} x \lambda dx = \frac{\lambda X^2}{2M} = \boxed{\frac{X}{2}}$$
A: You do that because of ${\rm d}m \propto {\rm d}x$ by means of linear mass factor $\lambda$. This means you can substitute $$\boxed{{\rm d}m = \lambda \,{\rm d}x}$$
$$ M = \int {\rm d}m = \int \lambda\, {\rm d}x $$
Where $\lambda$ is in units of mass per length, and usually a function of position $x$.
So the center of mass is
$$ X = \frac{1}{M} \int x\,{\rm d}m = \frac{1}{M} \int \lambda\, x\,{\rm d}x  $$
For a uniform rod with $\lambda = \text{(const)}$
$$ \left. M  = \int \lambda\, {\rm d}x = \lambda\, \ell \; \right\} \; \lambda = \frac{M}{\ell}$$
and 
$$ X = \frac{1}{M} \int \lambda\, x\,{\rm d}x = \frac{1}{M} \int \frac{M}{\ell}\, x\,{\rm d}x  = \frac{1}{\ell} \int x \, {\rm d}x = \frac{1}{\ell} (\tfrac{1}{2} \ell^2) = \tfrac{1}{2} \ell$$
A: If you want to go the "chopped up" route, first start with the discrete sum (ignoring the total mass term for now)
$$\sum_{i=1}^Nx_im$$
where $x_i$ is the center of section $i$. This is an important term to have here, as we will see. By the set up, $x_i=(i-1/2)\Delta x$, so we have
\begin{align}
\bar x&\propto \sum_{i=1}^Nm\left(i-\frac12\right)\Delta x\\
&=m\Delta x\sum_{i=1}^N\left(i-\frac12\right)\\
&=m\Delta x\left(\frac{N(N+1)-N}{2}\right)\\
&=m\Delta x\left(\frac{N^2}{2}\right)
\end{align}
Now, the total mass is given by $Nm$, and $\Delta x=X/N$, so we end up with
$$\bar x=\left(m\cdot\frac XN\cdot\frac{N^2}{2}\right)/(Nm)=X/2$$ with no integral needed.
However, I did this to point out how important the position of each mass is. In your integral where you just do $m\,\text dx$ you have completely removed all information about the position of each mass, because $\text dx$ is not the position of each mass element, just like how $\Delta x$ in the above example wasn't the position $x_i$ of each section, it would be like instead starting with the sum $\sum_{i=1}^N m\Delta x$, which doesn't tell you where any mass is. 
The $\Delta x$ or $\text dx$ is instead used to determine the location of each mass element. You can't just switch the integration variable without realizing this. This is why you need to specify some linear mass density function $\lambda(x)=\frac{\text dm}{\text dx}$ that can be used to indicate how much mass is located at each position as you do the integral over space. i.e. for the mass element at position $x$, $\lambda(x)\text dx=\text dm$ amount of mass is present, so then $x\,\text dm=x\lambda (x)\,\text dx\neq m\,\text dx$
In the discrete example with the uniform rod, $\lambda=M/X=Nm/X=m/\Delta x$. So to come full circle our sum of interest would have been
$$\sum_{i=1}^Nx_i\lambda\Delta x$$
And so there is your full analogy
$$\sum_{i=1}^Nx_im=\sum_{i=1}^Nx_i\lambda\Delta x$$
$$\int x\,\text dm=\int x\lambda\,\text dx$$
Also note that this is true for any change of variables. You cannot just exchange $m$ variables for $x$ variables and vice versa. You have to keep in mind how one variable varies with respect to the other. For example, in the usual "u-substitution" method taught in most introductory calculus classes, you have some proposed substitution $u=f(x)$, and so your differentials are related by $\text du=\frac{\text df}{\text dx}\text dx$.
