Adding to the above answer:
These mechanical devises are for thrust vectoring. Their purpose is for super-maneuverability, meaning that the aircraft can maintain pitch and yaw control at extreme angles of attack where other non super-maneuverable aircraft would stall, spin, completely loose control, etc.
This ultimately allows a wider flight envelope and the ability to "push the envelope" further than would be without thrust vectoring.
Thrust vectoring allows a plane to turn harder and faster because, rather than the control surfaces doing most of the work to turn the airframe, the engine exhaust becomes a large component in the vector change, thus reducing the load on the wings and the rest of the airframe. Loading the wings with high g turns is dangerous beyond the flight envelope - the vectoring eases the load and thus widens the envelope. Also, point the nozzles in opposing horizontal directions aids in rolling the aircraft.
Concerning your picture - the F-22 has '2D' thrust vectoring - allowing the exhaust to de deflected up and down over the horizontal axis and controlling 2 dimensions of flight dynamics (pitch and roll). Aircraft such as the MiG-29OVT (below) have '3D' thrust vectoring, allowing control of 3 dimensions of flight dynamics (pitch, roll, and yaw).
I've heard the MiG's nozzles are sometimes referred to as 'flowers of steel' because of the way they open, close, and move, sometimes completely independently of each other.
The video below shows the beautiful 3D nozzles in action starting at 1:40
Video: 3D Thrust Vectoring