shifting to a steady state
Separation of variables has a strict entry requirement: the boundary conditions must be homogeneous, meaning zero. Sines and cosines vanishing at the ends can only ever build a solution that is also zero at the ends, so if your bar is held at, say, 100 degrees on the left and 0 on the right, the raw eigenfunctions simply cannot match it. The fix is a clever bit of bookkeeping: peel off a fixed background that absorbs the awkward boundary values, leaving a remainder that IS zero at the ends and can be handled by the series.
Here is the recipe for the heat equation with fixed end temperatures u(0,t) = A, u(L,t) = B. First find the steady state v(x): the eventual, time-independent profile the bar settles into, which solves v'' = 0 with v(0) = A, v(L) = B — just the straight line v(x) = A + (B - A)x/L. Now write u(x,t) = v(x) + w(x,t). Substituting, w solves the SAME heat equation (because v contributes nothing to the time derivative and its second derivative is zero), but now with HOMOGENEOUS boundary conditions w(0,t) = w(L,t) = 0, since v already carries the boundary values. The transient w you solve by ordinary separation of variables, and its initial condition is the original initial data minus v(x).
So the full solution is the steady state plus a transient that decays away: u = v(x) + w(x,t), where w is a Fourier series whose every mode dies out in time. Physically this is exactly right — the bar relaxes toward its steady temperature profile, and the difference between now and forever-later is what the series describes. The same trick handles steady source terms (a constant heating) and other inhomogeneities: subtract a particular steady solution to homogenize the problem, then separate. It is the standard move that extends separation of variables past its homogeneous-boundary restriction.
A bar with ends held at u(0,t) = 0 and u(L,t) = 100 and any initial temperature. Steady state v(x) = 100 x / L (a straight line). Set u = v + w; then w solves the heat equation with w = 0 at both ends, and initial data w(x,0) = u(x,0) - 100 x / L. Solve w by a sine series; as t grows w decays to zero, and u relaxes to the straight-line profile v(x).
Peel off the steady state to make the boundary conditions zero; the leftover transient is a decaying Fourier series.
A steady state only exists when one can — for the insulated (Neumann) heat problem with mismatched flux, or with a time-DEPENDENT boundary value, there is no static v to subtract, and you need a more general approach (e.g. eigenfunction expansion with time-dependent coefficients, or Duhamel's principle).