# Quantum circuit to get expectation values of Pauli matrices, given state $|\psi\rangle$

I'm trying to solve 2 linear equations with the help of HHL algorithm. I've taken $$A=\begin{pmatrix} 1.5 & 0.5\\ 0.5 & 1.5\\ \end{pmatrix}$$ and $$b=\begin{pmatrix} 1\\ 0\\ \end{pmatrix}$$. I've implemented the circuit here, on quirk.

Question

How do I get expectation value of Pauli matrices in the above circuit?

To find the expectation value of a given Pauli matrix, you just measure in the basis defined by the Pauli matrix. For example, to evaluate the expectation value of the $$X$$ matrix, you find the basis vectors of the $$X$$ matrix. These are $$|+\rangle$$ and $$|-\rangle$$, with corresponding eigenvalues +1 and -1. You measure in the $$|\pm\rangle$$ basis many times and find the probability of getting either result, $$p_\pm$$. Then, finally, the expectation value is $$p_+-p_-$$ (the numbers multiplying the $$p_{\pm}$$ terms correspond to the eigenvalues).