Moment of inertia of a rod at an angle to the axis

suppose a uniform rod of mass M and lenght L is at an angle B to the x axis, one end of the the rod touching the axis. wish to find moment of inertia about x axis.

let the rod touches the axis at x=0. let D=density=M/L, and I will integrate along x axis, that means that at a distance x from the the origin, the little mass dM = D*dx is at a distance x*tanB away from the axis. then the integral I get is I = D*(x^2)*[(tanB)^2] integrated from x=0 to x=L*cosB. the answer I got is (1/3)*m*(L^2)*cosB*(sinB)^2.

I know this is different from the usual solution where one should integrate along the rod itself,but I dont understand which part of this argument went wrong?

Thanks!

Nugatory
Mentor
If you integrate dM across the same range that you're using to calculate the moment of inertia, what value do you expect?

Integrating along the x-axis instead of the rod is, of course, absolutely fine, however in this case your infinitesimal mass element dm should be dm = D*(dx/cosB), as each infinitesimal distance element dL along the length of the rod has a projection dx/cosB onto the x-axis.

With this in mind, the unwanted cosB factor of your result disappears, leaving the correct result of (1/3)*m*(L*sinB)^2