I've been trying to find a way to analytically find the unitary matrix of a circuit, but I cant find the resources to do so. How can I do so?
1 Answer
I will provide a short, incomplete answer on how to do it, but also refer you to resources that I would highly recommend you look at for a more complete picture. This will be an important skill for you to learn, so I would recommend taking your time to master it.
How to compute the unitary matrix of a circuit
Suppose a quantum circuit of $n$ qubits has $g$ unitary gates. Label these gates by $U_1, U_2, \dots, U_g$, in the order they occur in the circuit (if some gates occur simultaneously, it doesn't matter how you order those ones). Each of these gates has a representation as a $2^n \times 2^n$ unitary. To get $U$, just multiply these in reverse order: $U = U_g U_{g-1} \dots U_1$. The reversal comes from the way functions are ordered in standard math notation.
So how do you get the matrices $U_i$ in the first place? If it's a single-qubit gate, you could take the tensor product of the matrix for the single qubit with the identity on the rest of them, minding the ordering. Or, for any gate you could looking at how it acts on computational basis states.
Resources
If any of the above seems confusing or leave you with further questions, I would recommend the following resources to develop a strong foundation:
The Understanding Quantum Information and Computation course has video lectures and written material. It's free, available online, and at an introductory level, assuming background in linear algebra and complex numbers. By the end of Lesson 3, you should have the tools you need to answer your own question.
More advanced, but considered the standard resource, is Nielsen and Chuang's Quantum Information and Quantum Computation. Check out especially Chapters 2 and 4.