Collisionless heating occurs when a magnetoacoustic wave travels at right angles to a magnetic field in a plasma whose density is increasing in the direction of travel. Inclusion of pressure terms in a fluid description leads to an interaction of the wave with the density gradient which allows a net transfer of energy from the wave to the plasma. The mechanism is, however, reversible. Consequently a wave traveling out of the plasma is amplified, and the plasma loses energy to it. A method for obtaining a net transfer of energy to the plasma from a wave originating externally by varying the magnetic field strength is discussed along with the effect of the density gradient on other heating mechanisms.