For linear equations, the solution for f = cos(ωt) is the real part of the solution for f = e^iωt. That complex solution has magnitude G (the gain).