Minimizing the energy in a ruler I'm trying to find the shape a metal ruler takes when it is forced into certain specific boundary conditions.
Introduction
Imagine a long thin metal ruler, that is forced to bend around a number of nails that are nailed into a sheet of wood. The ruler will take on a certain shape to minimize its internal deformation energy.
The smaller the radius of curvature along the length $l$ of the ruler, the more energy is needed to force it into that shape. If $\theta$ is the angle that the ruler makes with the horizontal, we want to minimize its change, i.e., we want to minimize $$E = \int_0^L \left|\frac{d\theta}{dl}\right| dl = \int_0^X \left|\frac{d\theta}{dx}\right| dx.$$ Using $g(x)$ to describe the path of the ruler, we see that $\theta(x) = \arctan(g'(x))$. The change in the angle is therefore
$$ \frac{d\theta}{dx} = \frac{1}{1+g'(x)^2} g''(x). $$
So: whatever the boundary conditions, we want to find the function $g(x)$, so that $$E = \int_0^X \left|\frac{1}{1+g'(x)^2} g''(x)\right| dx$$ is minimal.
Now, without boundary conditions, this is trivial: due to the absolute value signs, the absolute minimum is $E=0$, which is obtained when $g''(x)=0 \forall x\in[0,X]$, i.e., when $g(x)$ is a straight line. Which is what's expected: the ruler is straight if there are no additional conditions it needs to fulfil.
It becomes more interesting with boundary conditions.
Boundary conditions

*

*The most natural boundary conditions, in line with how I initially presented the problem, is that there are several points $(a_i, y_i)$, and the condition is that, for all $i$, $$g(a_i) = y_i$$ This is an interesting problem, and already one I couldn't solve.


*For reasons I won't go into here (see this question if you're interested), the problem I'm actually trying to solve is one where there is a boundary condition on the integral of $g$. There are several tuples $(a_i, b_i, y_i)$, and the condition is that, for all $i$, we have $$\int_{a_i}^{b_i} g(x) dx = y_i \cdot (b_i-a_i)$$ I have no idea how to go about this, and would be grateful for any tips.
Many thanks!

EDIT:
Now, I'm not sure if it's actually helpful, but, solving the integral for E, we get
$$ \begin{align} E &= \int_0^X \left|\frac{1}{1+g'(x)^2} g''(x)\right| dx \\ 
&= \int_{I_+} \frac{1}{1+g'(x)^2} g''(x) dx + \int_{I_-} \frac{1}{1+g'(x)^2} (- g''(x)) dx \\
&= \left. \arctan(g'(x)) \right\vert_{I_+} - \left. \arctan(g'(x)) \right\vert_{I_-} \end{align} $$
With $I_+$ and $I_-$ the $x$-intervals where $g''(x)$ is positive and negative, respectively.
Because $I_+$ and $I_-$ form a continuous interval from $0$ to $X$, we can also write this as
$$
E = \arctan(g'(X)) - \arctan(g'(0)) - \left. 2 \arctan(g'(x)) \right\vert_{I_-}  
$$
Our goal is to find the function $g(x)$ that minimizes this expression while conforming to the boundary conditions.
 A: Euler-Bernoulli Law defines a linear relation with a proportionality constant ( flexural rigidity EI) between curvature (whose arc integrand is the slope $ \theta$ you mention) and the Bending Moment (blue).
Nails at black dot points (deformation) in plywood eventually define forces using well developed approaches of Mechanics of Materials / Strength of Materials starting 18th century...on materials like a fiberglass bar or elastic metal ruler. At these fixed points (called simply supported or hinged )the bending moment vanishes.
A simple program listing in Mathematica is given where at simple support arc lengths $ (s=-2,s=-1,s=1) $ the moments vanish. Integration is done by NDSolve using Runge-Kutta numerical integration algorithms.

The NDSolve numerically integrates automatically from second to first (slope) derivative and next to $ [x(s),y(s)], \dfrac{dx}{ds}= \cos \theta,\;\dfrac{dy}{ds}= \sin \theta,\;$ and the shape of curve of deflection is seen.
EI=3;smin=-2;smax=1.5;
bm[s_]= -EI (s-1)(s+1)(s+2)/3;
BdgMoment=Plot[bm[s],{s,smin,smax},PlotStyle->{Thick,Blue},GridLines->Automatic,AspectRatio->0.6]
equn={PH'[s]==bm[s]/EI,X'[s]==Cos[PH[s]],Y'[s]== Sin[PH[s]],PH[0]==0.5,X[smin]==-2,Y[smin]==2};
NDSolve[equn,{PH,X,Y},{s,smin,smax}];
{ph[u_],x[u_],y[u_]}={PH[u],X[u],Y[u]}/.First[%];
deflection=ParametricPlot[ {x[s],y[s]},{s,smin,smax+.4},PlotStyle->{Red,Thick},GridLines->Automatic,AspectRatio->0.4 ]

Static equilibrium shapes come about automatically by energy minimization of elastic strain energy stored $ U=\int \frac{M^2}{2 EI} ds$.  A set of forces can be found that produce a moment distribution of the first figure.

By action of the forces (omitted here), the (blue) bending moments come about. These moments determine curvatures from point to point. So by such direct integration an Elastica (Euler) type shape (red) can be arrived at as shown. I have included three nails  but they can be generalized to  arbitrary numbers and positions.
For small rotations a solution of elastic curve (aka "beam") due to Prof. Hetényi / MIT reminds one  of the Maclaurin's series:
$$ y(x) = y_0 + y'_0(x) +-y''(0) \frac{x^2}{2!}- y'''(0)\dfrac{x^3}{3!}..$$
where the third and fourth derivatives  represent bending moment and shear force upto the constant EI.
Your approach that virtual work/energy decides shape of elastic rulers is basically correct. However, the forces need to be brought in. There are theorems of Castiliagno that link energy ( its partial derivative with respect to forces ) to determine the deformation/shape.
I am sure my answer creates  more questions but in view of the range of details involved, that is about the best I could present for now.
