Volume of Square-based Pyramid Using Integration I tried to find the volume of a square-pyramid using integration by summing up triangular prisms, but for some reason I am not getting the right answer.
Below is my approach:
Suppose I place my triangular prism on an (x,y,z) coordinate system where one side of the base is co-linear to my x-axis, and the other side is co-linear to the y-axis. 
I can create a linear equation that represents the height of my pyramid at a particular point x which passes through the summit of the pyramid. That is, I know that when x=0, y=0, and when x=$\frac{b}{2}$, y=h. 
Therefore the equation of the line is y=$\frac{2h}{b}x$. The area of a triangular prism is $A_b \times thickness$. To calculate the volume of the pyramid, my approach is to just sum up a bunch of thin triangular prisms.
For a particular value x between 0 and $\frac{b}{2}$, the volume of a triangular prism slice would be $\frac{b2hx}{2b}dx$, which simplifies to $hxdx$.
We then integrate between 0 and $\frac{b}{2}$ which gives us the volume up to the summit, and multiply by 2 because of symmetry.
$2\int_0^\frac{b}{2}hxdx=2h\int_0^\frac{b}{2}xdx=2h\frac{b^2}{8}=\frac{1}{4}hb^2$
Where did I go wrong in my approach of summing triangular prisms together? Or is it that triangular prisms somehow do not work for finding volumes?
 A: If you want to find the volume using integration you can integrate in $z$ axis by summing the trapezoidal cross sections. [Assuming the base of the pyramid is a square]
Suppose highest point of the pyramid is $(0,0,0)$. Assume the pyramid is upside down. Now we can find a function which gives us the length of the base of trapezoidal cross section. As at $y=0, x=0$ and $y=h, x=b$ the function would be $y=\frac{b}{h}x$
Now the volume of the cross section of $dx$ thickness would be 
$$ \left( \frac{b}{h}x \right)^2 dx $$
Now the area of the pyramid would be-
$$\int_{0}^{h} \left( \frac{b}{h}x \right)^2 dx = \frac{b^2}{h^2} \int_{0}^{h}x^2 dx = \frac{b^2}{h^2} \frac{x^3}{3}=\frac{b^2 \times h^3}{3 h^2} = \frac{b^2 h}{3}$$ 

Now why did your method gave a wrong answer? If I am not wrong summing the prisms will make a 3D shape with many prism side by side each having the same $dx$ base and height would increase due to $y=\frac{2h}{b}x$. The face of the 3D same will look kinda like this.

There for the value you get is half of the volume of a prism with a face area $\frac{1}{2} h \times b$ and thickness $b$ 
A: If you're amenable to a multivariate approach, you can place the base of the pyramid in the $x,y$ plane so that the vertices of the base are located at $\left(\pm\frac\ell{\sqrt2},0,0\right)$ and $\left(0,\pm\frac\ell{\sqrt2},0\right)$, and the apex is at $\left(0,0,h\right)$, where $\ell$ is the length of one side of the base and $h$ is the height of the pyramid.
Then the volume of the pyramid is $4$ times the volume of the tetrahedral chunks in each of the four octants above the $x,y$ plane. The chunk in the first octant is bounded by the planes $x=0$, $y=0$, $z=0$, and $\frac{\sqrt2}\ell x+\frac{\sqrt2}\ell y+\frac1hz=1$, and the volume of this chunk is
$$T=\int_0^{\frac\ell{\sqrt2}}\int_0^{\frac\ell{\sqrt2}-x}\int_0^{h-\frac{\sqrt2h}\ell x-\frac{\sqrt2h}\ell y}\mathrm dz\,\mathrm dy\,\mathrm dx=\frac{h\ell^2}{12}$$
and so the total volume would be $P=4T=\dfrac{h\ell^2}3$.
