Matrix ansatz and large deviations of the density in exclusion processes