Linear-response functions and second-order transition amplitudes can be calculated exactly provided one effective state, the solution of an inhomogeneous Schrodinger equation, is known. We show how variational principles can be applied to the calculation of this effective state; an important advantage is the possibility of using variational techniques, which are very efficient when large basis sets (such as plane waves) are used, or when the solution is required as a function of a free parameter (for instance, the frequency in dynamical response functions). The variational principle applies to solid-state as well as to atomic problems. We illustrate the use of one variational technique in the simple case of two-photon transitions in the hydrogen atom.