Find the largest cylinder inscribed inside a sphere. Is this calculation correct so far? 
A right circular cylinder is inscribed in a sphere of radius $r$. Find the largest possible volume of such a cylinder.

I have that the radius of the cylinder is $r$, the radius of the sphere is $R$, and the height of the inscribed cylinder is $h$. So
$$(2r)^2+h^2=(2R)^2$$
$$4r^2 + h^2 = 4R^2$$
$$h=2\sqrt{R^2-r^2}$$
So volume of the cylinder is:
$$V=2\pi r^2\sqrt{R^2-r^2}$$
$$V'=4\pi r\sqrt{R^2-r^2}+2\pi r^2\frac d{dr}\sqrt{R^2-r^2}$$
And I think:
$$\frac d{dr}\sqrt{R^2-r^2}=\frac r{\sqrt{R^2-r^2}}$$
so
$$V'=4\pi r\sqrt{R^2-r^2}+\frac{2\pi r^3}{\sqrt{R^2-r^2}}$$
$$=4\pi r(R^2-r^2)+2\pi r^3$$
$$4\pi rR^2-4\pi r^3+2\pi r^3=4\pi rR^2-2\pi r^3$$
So finding critical values:
$$4\pi r R^2-2\pi r^3=0$$
$$4\pi r R^2=2\pi r^3$$
$$4\pi R^2=2\pi r^2$$
$$\frac{4\pi R^2}{2\pi}=r^2$$
$$r=\sqrt2R$$
Someone else who is better at math is getting $r=\sqrt{\frac23}R$. Where did I go wrong?

You might enjoy the fact that you actually do not need derivatives. By the AM-GM inequality
$$V^2=16\pi^2\cdot \frac{r^2}{2}\cdot \frac{r^2}{2}\cdot(R^2-r^2)\leq 16\pi^2\left(\frac{R^2}{3}\right)^3 $$
i.e. $V\leq \frac{4\pi R^3}{3\sqrt{3}}$, with equality attained at $\frac{r^2}{2}=R^2-r^2$, i.e. at $r=R\sqrt{\frac{2}{3}}$.
