Approximation of beam Assume that there is a simply supported beam subjected to concentrated moments $M_0$ at each end. The governing equation is
$$EI\frac{d^2y}{dx^2}-M(x)=0$$
with the boundary conditions $y(0)=0$ and $y(H)=0$. I know that there is an exact solution in the form of $y(x)=\frac{M_0\,x}{2EI}(x-H)$ but I must find an approximate solution for the deflection of the beam using trigonometric functions via Least Squares Method. The least squares method is known to me in general; but how to use it in this case?
 A: Suppose that $\hat y(x)$ is an approximate solution then it follows that
$$EI\frac{d^2 \hat y}{dx^2}-M(x)=R(x)\ne 0$$
since the approximate solution does not satisfy the equation. In LSM the error term is defined such as
$$I=\int_a^b R(x)^2 dx$$
and minimized wrt to coefficients in $\hat y(x)$. To satisfy the boundary constraint the approximation function can be taken as (Note that you can have more parameters and satisfy the boundary constraints later on)
$$\hat y(x)=a\sin\bigg(\frac{\pi\,x}H\bigg)$$
By noting that $M(x)$ has a constant value $M_0$ 
$$I=\int_0^H \bigg(EI\frac{d^2 \hat y}{dx^2}-M_0\bigg)^2 dx=\int_0^H \bigg(-EI\frac{a\pi^2}{H^2}\sin\bigg(\frac{\pi\,x}H\bigg)-M_0\bigg)^2 dx$$
Now use Wolfram Alpha to integrate (or use below result)
$$I=\frac{E^2\,I^2\,\pi^4}{2\,H^3}a^2+\frac{4\,M_0\pi\,E\,I}Ha+M_0^2\,H$$
For minimization use the derivative wrt $a$
$$\frac{d\,I}{d\,a}=\frac{E^2\,I^2\,\pi^4}{H^3}a+\frac{4\,M_0\pi\,E\,I}H=0\Rightarrow a=-\frac{4\,M_0\,H^2}{\pi^3\,E\,I}$$
and the approximate function becomes
$$\hat y(x)=-\frac{4\,M_0\,H^2}{\pi^3\,E\,I}\sin\bigg(\frac{\pi\,x}H\bigg)$$
