# Why does solving linear systems of equations with HHL return imaginary numbers? [closed]

The textbook shows an example system of linear equations $$Ax=b$$ with

$$A=\begin{pmatrix} -\frac{1}{3} & 1 \\ 1 & -\frac{1}{3} \end{pmatrix} \,\,\,\, b=\begin{pmatrix} 0 \\ 1 \end{pmatrix}.$$

The program in the text shows a result in real numbers. When trying to run a larger $$A$$ matrix and $$b$$ matrix, the output includes complex numbers even though the actual answer (calculated using numpy linear equation solver) shows no complex numbers. Where are these imaginary numbers coming from?

• Without more details of the case you've tried, and the code you've run, it may be hard to track down. However, one quick thing to check - is it that your output $x$ is a real vector, but every element is multiplied by the same complex phase $e^{i\theta}$? Feb 16, 2021 at 7:28
• The code im running is the HHL code in the qiskit textbook, section 4A:Running HHL on a simulator (qiskit.org/textbook/ch-applications/hhl_tutorial.html). By replacing the matrix and vector: matrix = [[1, 1, 1, 2, 2, 3], [-5, 5, 6, 6, 6, -1], [3, 6, 2, 8, 8, 4], [2, 5, -3, 2, 4, 3], [1, 3, 2, 3, -2, 3], [12, 7, 1, 3, 3, 2]] and vector = [2,1,-2,2,1,2], the output solution includes complex numbers. Feb 16, 2021 at 18:02