<s>[INST] What is the expected length of the hypotenuse formed by bending a unit length randomly at a right angle? This is easy enough to simulate and find the answer is somewhere around .812. However I am not finding it so easy to solve the integral involved which I believe is...
$$\int_0^1 \sqrt{x^2+(1-x)^2} dx$$
I don't seem to get the right answer if I use this derivation. Bonus points for finding the expected area which is a much easier problem!
 [/INST] $$\begin{align}I&=\int_0^1 \sqrt{x^2+(1-x)^2} dx\\
&=\int_0^1\sqrt{2x^2-2x+1}dx\\
&=\int_0^1\sqrt2\sqrt{\left(x-\frac12\right)^2+\frac14}dx\end{align}$$
Let $x-\frac12=\frac12\tan\theta$. Then, $dx=\frac12\sec^2\theta d\theta$.
$$\begin{align}I&=\frac{1}{2\sqrt2}\int_{-\frac{\pi}{4}}^{\frac{\pi}{4}}|\sec\theta|\sec^2\theta d\theta\\
&=\frac{1}{2\sqrt2}\int_{-\frac{\pi}{4}}^{\frac{\pi}{4}}\sec^3\theta d\theta\\
\end{align}$$
which can be integrated by parts.
Then,
$$\begin{align}I&=\frac{1}{2\sqrt{2}}\left(\frac12\sec\theta\tan\theta+\frac12\ln|\sec\theta +\tan\theta|\right)|_{-\frac{\pi}{4}}^{\frac{\pi}{4}}\\
&=\frac{1}{2\sqrt{2}}\left(\sqrt{2}+\frac12\ln\left|\frac{\sqrt2+1}{\sqrt2-1}\right|\right)\end{align}$$
</s>