<s>[INST] 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?
 [/INST] You made a sign error in computing the derivative of $\sqrt{R^2-r^2}$.
$$\frac d{dr}\sqrt{R^2-r^2}=\frac{-r}{\sqrt{R^2-r^2}}$$
Thus
$$V'=4\pi r\sqrt{R^2-r^2}-\frac{2\pi r^3}{\sqrt{R^2-r^2}}=0$$
$$4\pi r(R^2-r^2)-2\pi r^3=0$$
$$2(R^2-r^2)=r^2$$
$$2R^2=3r^2$$
$$r=\sqrt{\frac23}R$$
</s>