I'm trying to understand the derivation of Timoshenko beam equation on Wikipedia.
At one point we arrive at the following:
$$ \int_L \left[\left(\frac{\partial M_{xx}}{\partial x} - Q_x\right)~\delta\varphi - \left(\frac{\partial Q_{x}}{\partial x} + q\right)~\delta w\right]~\mathrm{d}L = 0 $$
where the integral is taken along the length $L$ of the beam. The moment $M_{xx}$, the shear force $Q_{x}$ and the variations on the beam angle and deflection, $\delta \varphi$ and $\delta w$, are functions of $x$.
Then:
The governing equations for the beam are, from the fundamental theorem of variational calculus,
$$ \frac{\partial M_{xx}}{\partial x} - Q_x = 0 ~;~~ \frac{\partial Q_{x}}{\partial x} + q = 0 $$
I know the fundamental theorem/lemma of variational calculus is: If a smooth function $f(x)$ satisfies the following formula for any $h(x)$ with certain properties on the interval between $a$ and $b$, then $f(x)=0$.
$${\displaystyle \int _{a}^{b}f(x)h(x)\,\operatorname {d} x=0}$$
So, as I understand, the function $h(x)$ can be any arbitrary function on the interval as long as it vanishes outside the interval. The above identity has to hold for all such functions.
But beam theory specifically assumes that deflections of the beam are small. Functions $\delta \varphi$ and $\delta w$ therefore must be (infinitesimally) small along the beam. So how can we apply the fundamental lemma to he first equation if the lemma requires that $h(x)$ can be any, even arbitrarily large, function?
Requiring $h$ to be any function is not necessary. All you need is $h$ with support on arbitrary intervals, their size is irrelevant. I recommend you go over the proof of the lemma and convince yourself.