Typical situations in which a density matrix is needed include: a quantum system in thermal equilibrium (at finite temperatures), nonequilibrium time-evolution that starts out of a mixed equilibrium state, and entanglement between two subsystems, where each individual system must be described by a density matrix even though the complete system may be in a pure state.
The density matrix (commonly designated by ρ) is an operator acting on the Hilbert space of the system in question. For the special case of a pure state, it is given by the projection operator of this state. For a mixed state, where the system is in the quantum-mechanical state |ψj〉 with probability pj, the density matrix is the sum of the projectors, weighted with the appropriate probabilities (see bra-ket notation):
ρ = ∑j pj |ψj〉〈ψj|
The density matrix is used to calculate the expectation value of any operator A of the system, averaged over the different states |ψj〉. This is done by taking the trace of the product of ρ and A:
tr[ρ A]=∑j pj 〈ψj|A|ψj〉
The probabilities pj are nonnegative and normalized (i.e. their sum gives one). For the density matrix, this means that ρ is a positive semidefinite hermitian operator (its eigenvalues are nonnegative) and the trace of ρ (the sum of its eigenvalues) is equal to one.