# Given a three-qubit state, how do you obtain the density matrix for the third qubit

I have a quantum simulator that yields a three-qubit final state. However, I need to measure the first two qubits and apply a one-qubit gate (x,y or z) to the third qubit. How do you reduce a three-qubit state to a one-qubit state by measuring the first two qubits?

Given a multipratite state $$\rho$$, its reduced density matrix is the partial trace with respect to some of its degrees of freedom. If $$\rho$$ is bipartite, then the partial trace with respect to its first degree of freedom is the matrix with elements $$[\operatorname{Tr}_1(\rho)]_{ij} = \sum_k \rho_{ik,jk}.$$ If you have a multipartite state (e.g. a three-qubit one) you apply the above with respect to some bipartition. In the case you consider, you are doing the partial trace with respect to first and second degrees of freedom.