I recently learned about a technique to use ODEs to find the mathematical expectation. I decided to apply it to the following problem:
Let $X_1$, $X_2$, $\ldots\simeq$ Uniform$(0,1)$ iid. Let $N$ be the first index $n$ where $X_n\neq \max\{X_1,X_2,\ldots,X_n\}$. Find $E[N]$.
To solve, we generalize the problem by defining a function $m(z)$. The function $m(z)$ is the expected number of uniform variables needed so that the monotonic condition no longer holds when initially starting at $z$. Specifically, it is the average of the first index $n$ such that $X_n<X_{n-1}\geq\ldots X_1\geq z$. Then the total law of expectation - where we condition on $X_1$ - yields
$$m(x) = \int^1_x(1+m(z)) \mathrm{d}z$$
For now, let us assume that $m(x)$ is differentiable. Then differentiating both sides yields
$$m'(x)=-(1+m(x))$$ or $$m'(x)+m(x)=-1$$
This is a linear ODE with general solution $m(x)=ce^{-x}-1$. Plugging this equation back into the integral shows that
$$\int^1_z(1+m(z))\;\mathrm{d}z=-ce^{-1}+ce^{-z}=ce^{-x}+1$$
or $c=e$. All the remains to do is to evaluate at $x=0$:
$$m(0)=e^{1-0}-1=e-1$$
However, solving it through alternative means, I obtain $e$. What went wrong?
\begin{gather*} m(x)= E[N\mid X_1>x]=\frac{1}{1-x}\int^1_x E[N\mid X_1=z]dz=\\ =\frac{1}{1-x}\int^1_x \left(E[N\mid X_1=z, X_2<X_1]z +E[N\mid X_1=z, X_2\geq X_1](1-z) \right)dz=\\ =\frac{1}{1-x}\int^1_x \left(2z +(1+m(z))(1-z)\right)dz \end{gather*} Differentiating: $$(1-x)m'(x)= xm(x)-x-1$$ Whose solution is: $$m(x)=\frac{e^{1-x}-x}{1-x}$$