Governing d.e is,
$\frac{d}{dx} [AE \frac{du}{dx}] = 0 \\
AE \frac{d^2u}{dx^2} = 0\\
AE \frac{d^2u}{dx^2} = 0$
$AE \frac{du}{dx} |-{\bar{x} = 0} = -P^e_1 \hspace{0.5cm} \Rightarrow \hspace{0.5cm} \frac{du}{dx} |_{\bar{x} = 0} = \frac{-P_1}{AE}$
$AE \frac{du}{dx} |-{\bar{x} = he} = -P^e_2 \hspace{0.5cm} \Rightarrow \hspace{0.5cm} \frac{du}{dx} |_{\bar{x} = he} = \frac{-P_2}{AE}$
$R = AE \frac{du^2}{dx^2}$
$\int\limits^{he}_0 WiR d \bar{x} = \int\limits_0^{he} Wi (AE \frac{d^2u}{dx^2})d \bar{x} = 0\\
\hspace{0.5cm} = \Big[ Wi AE \frac{du}{dx} \Big]_0^{he} - \int\limits_0^{he} \frac{dWi}{d \bar{x}}. AE \frac{du}{d \bar{x}} d \bar{x} = 0$
Let $u = u_1 \phi_1 + u_2 \phi_2$
$\phi_1 = 1 - \frac{\bar{x}}{he} \hspace{0.5cm} and \hspace{0.5cm} \phi_2 = \frac{\bar{x}}{he}\\
\frac{d \phi_1}{d \bar{x}} = - \frac{1}{he} \hspace{0.5cm} and \hspace{0.5cm} \frac{d \phi_2}{d \bar{x}} = \frac{1}{he}$
For Rayleigh Fits method:-
$Wi = \phi_1$
For $i = 1, W_1 = \phi_1 = 1 - \frac{\bar{x}}{he}$
$\therefore \frac{dW_1}{d \bar{x}} = - \frac{1}{he}$
For $i = 2, W_2 = \phi_2 = \frac{\bar{x}}{he}$
$\therefore \frac{dW_2}{d \bar{x}} = \frac{1}{he}$
For i = 1
$\bigg[ \Big(1 - \frac{\bar{x}}{he}\Big)\Big(AE \frac{du}{d \bar{x}}\Big)\bigg]_0^{he} - \int\limits_0^{he}(- \frac{1}{he})AE \frac{d}{dx}\bigg[ u_1 (1 - \frac{\bar{x}}{he})+ u_2 \frac{\bar{x}}{he}\bigg] d \bar{x} = 0$
$[ 0 - (- P_1)] - AE \int\limits^{he}_0 (- \frac{1}{he})(- \frac{u_1}{he} + \frac{u_2}{he})d \bar{x} = 0$
$AE\bigg( \frac{u_1}{he} - \frac{u_2}{he}) = P_1\\
\frac{AE}{he}(u_1 - u_2) = P_1 \hspace{2cm} --------- (2)$
For i = 2
$\bigg[ \Big(\frac{\bar{x}}{he}\Big)\Big(AE \frac{du}{d \bar{x}}\Big)\bigg]_0^{he} - \int\limits_0^{he}(\frac{1}{he})a \frac{d}{d \bar{x}}\bigg[ u_1 (1 - \frac{\bar{x}}{he})+ u_2 \frac{\bar{x}}{he}\bigg] d \bar{x} = 0$
$[P_2] - AE \int\limits^{he}_0 (\frac{1}{he})(- \frac{u_1}{he} + \frac{u_2}{he})d \bar{x} = 0$
$AE\bigg(\frac{u_1}{he} + \frac{u_2}{he}) = P_2\\
\frac{AE}{he}(u_1 + u_2) = P_2 \hspace{2cm} --------- (3)$
Putting eq. (2) and (3) in matrix form,
$\frac{AE}{he} \begin{bmatrix} \ 1 & -1 \\ \ -1 & 1 \\ \end{bmatrix} \begin{Bmatrix} \ u_1 \\ \ u_2 \\ \end{Bmatrix} = \begin{Bmatrix} \ P_1 \\ \ P_2 \\ \end{Bmatrix}$
For 2 linear elements,
Elemental matrix for element no. 1
$\frac{AE}{he_1} \begin{bmatrix} \ 1 & -1 \\ \ -1 & 1 \\ \end{bmatrix} \begin{Bmatrix} \ u_1 \\ \ u_2 \\ \end{Bmatrix} = \begin{Bmatrix} \ P_1 \\ \ P_2 \\ \end{Bmatrix}$
Elemental matrix for element No. 2
$\frac{AE}{he_2} \begin{bmatrix} \ 1 & -1 \\ \ -1 & 1 \\ \end{bmatrix} \begin{Bmatrix} \ u_2 \\ \ u_3 \\ \end{Bmatrix} = \begin{Bmatrix} \ P_2 \\ \ P_3 \\ \end{Bmatrix}$
Global matrix elemental,
$AE \begin{bmatrix} \ \frac{1}{he_1} & - \frac{1}{he_1} & 0 \\ \ -\frac{1}{he_1} & \frac{1}{he_1} + \frac{1}{he_2} & -\frac{1}{he_2} \\ \ 0 & -\frac{1}{he_2} & \frac{1}{he_2} \\ \end{bmatrix} \begin{Bmatrix} \ u_1 \\ \ u_2 \\ \ u_3 \\ \end{Bmatrix} = \begin{Bmatrix} \ F_1 \\ \ F_2 \\ \ F_3 \\ \end{Bmatrix}$
Boundary conditions are $u_1 = 0$
Solve for $u_2$ and $u_3$