# Finding moment of inertia of a cone: Why can't I integrate like this?

I have a cone (vertex at $$(x,y,z)=0$$) with height $$H$$ and radius $$a$$ (radius of the base). Here is a picture:

I want to find the moment of inertia around the $$z$$-axis using calculus. I know the integral I have to evaluate is :$$I_z={\int \int \int}_V \vec{r}^2 dm$$

I decided to switch to cylindrical coordinates and my integrals becomes:

$$I_z={\int_0^H \int_0^{2\pi} \int_0^{\color{red}{?}}} r^3 dr d \theta dz$$

Since my radius is changing with $$z$$ I need to parameterize $$r$$ in terms of $$z$$. By similar triangles we have $$\frac{a}{H}=\frac{r(z)}{z} \iff r(z)=\frac{a z}{H}$$

When I tried to do this exercise without any help I substituted $$r^3$$ with $$r(z)^3=\left( \frac{az}{H}\right)^3$$:

$$\implies I_z={\int_0^H \int_0^{2\pi} \int_0^{\color{red}{a}}} \left( \frac{az}{H}\right)^3 dr d \theta dz$$

However, this seems to be wrong and I know the correct way to write the integral is this:

$$I_z={\int_0^H \int_0^{2\pi} \int_0^{\color{red}{\frac{az}{H}}}} r^3 dr d \theta dz$$

I don't understand what's wrong with my method and I don't really understand why the upper bound of the integral w.r.t $$r$$ is $$\frac{az}{H}$$? Why is it not just the radius $$a$$ of the base? What am I getting wrong here?

For a differential mass $$dm$$, the moment of inertia is $$r^2dm$$ or $$\rho r^2dV$$. In cylindrical coordinates $$dV=r \ dr\ d\varphi \ dz$$. So:
$$dI=\rho r^3\ dr\ d\varphi \ dz$$
$$I=\rho\int_0^{2\pi} d\varphi\int_0^H dz\int_0^{az \over H} r^3\ dr$$
Why do you have to put $$\frac{az}{H}$$ as the upper limit? If you put just $$a$$ you would actually calculate the moment inertia of a cylinder of radius $$a$$! Look at the range of values that $$r$$ can take when you move $$dm$$ inside the cone. At level $$z=0$$ the maximum distance of $$dm$$ from the vertical axis is 0. At level $$z=H$$ the value of $$r$$ varies between 0 and $$a$$. But to calculate the integral properly, you need limits for $$r$$ in an arbitrary position defined by an arbitrary value of $$z$$ (next variable in the order of integration). For arbitrary height $$z$$ the distance of $$dm$$ from the vertical axis varies from 0 to $$az/H$$ and that is the upper limit of the third integral..