Given D.E. $ \frac{d}{dx}[K \frac{dT}{dx}] = q $ for 0 $\leq$ x $\leq$ i.e. $ \frac{d}{dx}[K \frac{dT}{dx}] - q = 0 $
In local co-ordinates, replace $dx$ by $d \bar{x}$
$ \frac{d}{d \bar{x}}[K \frac{dT}{d \bar{x}}] - q = 0 $
With local boundary conditions as,
$ K \frac{dT}{d \bar{x}}|_{\bar{x}=0} = - \frac{Q_1}{A} $
$ K \frac{dT}{d \bar{x}}|_{\bar{x}=he} = \frac{Q_2}{A} $
Since the solution is approximate, residue is given by,
$ \frac{d}{d \bar{x}}[K \frac{dT}{d \bar{x}}] - q = R $
Weighted integral form,
$ \int_0^1 w_iR \,\, dx = 0 $
$ \int_0^{he} w_i (\frac{d}{d \bar{x}}[K \frac{dT}{d \bar{x}}] - q ) \,\, d \bar{x} = 0 \\
\int_0^{he} w_i (\frac{d}{d \bar{x}}[K \frac{dT}{d \bar{x}}]) \,\, d \bar{x} - \int_0^{he}w_iq \,\,d \bar{x} = 0 \hspace{0.5cm} ....(1) $
Weak formulation
Consider equation, $ \int_0^{he} w_i (\frac{d}{d \bar{x}}[K \frac{dT}{d \bar{x}}]) \,\, d \bar{x} $
Integrating by parts, we get,
$ [w_i(K \frac{dT}{d \bar{x}})]_0^{he} - \int_0^{he} \frac{dw_i}{d \bar{x}}[w_i(K \frac{dT}{d \bar{x}})] \,\, d \bar{x} $
Substituting above value in eq(1), we get,
$ [w_i(K \frac{dT}{d \bar{x}})]_0^{he} - \int_0^{he} \frac{dw_i}{d \bar{x}}[w_i(K \frac{dT}{d \bar{x}})] \,\, d \bar{x} - \int_0^{he} w_iq \,\, d \bar{x} = 0 \hspace{0.5cm} ....(2) $
Let the approximate solution be,
$ T = T_1 \phi_1 + T_2 \phi_2 $
where $ \phi_1 = 1 - \frac{\bar{x}}{he}; \hspace{0.5cm} \phi_2 = \frac{\bar{x}}{he} $
Rayleigh-Ritz method, $ w_i = \phi_1 $
For i = 1, $ w_1 = 1 - \frac{\bar{x}}{he}; \hspace{0.5cm} \frac{dw_1}{d \bar{x}} = - \frac{1}{he} $
Substituting in eq(2), we get,
$ \frac{Q_1}{A} - K \int_0^{he} ( \frac{-1}{he}) (- \frac{T_1}{he} + \frac{T_2}{he}) \,\, d \bar{x} - \int_0^{he} (1 - \frac{\bar{x}}{he}).q \,\, d \bar{x} = 0 \\
\frac{Q_1}{A} = \frac{-K}{he}[\frac{-T_1 \bar{x}}{he} + \frac{T_2 \bar{x}}{he}]_0^{he} - q[\bar{x} - \frac{(\bar{x})^2}{2he}]_0^{he} \\
\frac{Q_1}{A} = \frac{-K}{he}[-T_1 + T_2] - q[\frac{he}{2}] $
or
$ \frac{Q_1}{A} = \frac{K}{he}[T_1 - T_2] - q \frac{he}{2} \\
\frac{K}{he} [T_1 - T_2] = \frac{Q_1}{A} + q \frac{he}{2} \hspace{0.5cm} ...(3) $
For i = 2, $ w_2 = \frac{\bar{x}}{he}, \hspace{0.5cm} \frac{dw_2}{d \bar{x}} = \frac{1}{he} $
Substituting in eq(2), we get,
$ \frac{Q_2}{A} - K \int_0^{he} \frac{1}{he}( \frac{-T_1}{he} + \frac{T_2}{he}) d \bar{x} - \int_0^{he} \frac{ \bar{x}}{he}q \,\, d \bar{x} \\
\frac{Q_2}{A} = \frac{K}{he} [ \frac{-T_1 \bar{x}}{he} + \frac{T_2 \bar{x}}{he}]_0^{he} - \frac{q}{he}[ \frac{ ( \bar{x})^2}{2}]_0^{he} \\
\frac{Q_2}{A} = \frac{K}{he}[-T_1 + T_2] - \frac{q(he)}{2} $
or
$ \frac{K}{he}[-T_1 + T_2] = \frac{Q_2}{A} +\frac{q(he)}{2} \hspace{0.5cm} ....(4) $
Putting eq (3) and (4) in matrix form, we get,
$
\frac{K}{he}
\begin{bmatrix}
1 & -1 \\
-1 & 1
\end{bmatrix}
\begin{Bmatrix}
T_1 \\ T_2
\end{Bmatrix}
=
\begin{Bmatrix}
\frac{Q_1}{A} \\ \frac{Q_2}{A}
\end{Bmatrix}
+
\frac{q(he)}{2}
\begin{bmatrix}
1 \\ 1
\end{bmatrix}
$