There are a couple of things going on here. First, the \ operator uses floating point arithmetic. So you can only expect A*x to be approximately equal to B. Secondly, your matrix appears to be singular, or numerically very close to being singular. In julia I get
julia> rank(A)
2
In this case, the \ manages to produce a solution but it’s meaningless. Here’s an example with a full rank matrix, where you can expect a reasonably accurate solution:
Note that in this case the solution is accurate but A*x == B still returns false because the solution is only accurate up to machine precision. It’s not the exact solution. I suggest reading up on numerical linear algebra to get a better sense of what’s going on here.
I knew that the system was inconsistent so I was expecting an error to be thrown instead of a nonsense value to be returned. For some other examples of inconsistent systems the operator throws a SingularException(n), such as
I was curious how other languages would handle the linear system.
Matlab gave a warning that the matrix is singular to working precision and returned [NaN, Inf, -Inf].
Numpy with linalg.lstsq gave [ 1.43722944, 2.05627706, -1.83549784] but it also returns the rank with the fit (2 in this case).
If you are doing linear algebra with matrices that might be ill-conditioned, you really need to think carefully about why that is happening in order to choose an appropriate course of action.