A has 5 lines, and therefore D Both of them have 3 columns. Therefore, you have an overridden system of 5 equations with 3 variables. In most cases, this means that you cannot solve the equations exactly because you have too many limitations.
As soon as you do
x = A\D;
you get the least squares solution.
0.8333 -1.5000 1.6667
What is the solution? This is a solution that minimizes the sum of squared errors. Let me calculate the error:
r = A*xD; totalError = sum( r.^2);
This means that you cannot find x so that sum(sqr(A*xD)) has a smaller error.
A short note: in your case, you also have a string of zeros - which leads to the fact that the actual number of equations becomes 4
Let's look again at A*(A\D) :
>> A* (A\D) ans = 1.0000 0 3.5000 3.5000 5.0000
It looks familiar! Very close to [1; 2; 3; 4; 5]. The first and last lines are the same. The second value is zero because you put a string of zeros. In the 3rd and 4th lines you had exactly the same lines in A, but a different value in B, which corresponds to
2*x+ 1*y + 2*z = 3; 2*x+ 1*y + 2*z = 4;
And you have their average! This makes sense because the average is a value that minimizes the sum of the distances to 3 and 4.
Here is a simpler example: suppose you want to solve the following system of equations:
x = 1; x = 2;
Obviously, x cannot be 1 and 2 at the same time. A solution that minimizes the sum of the squared errors is 1.5
A = [1;1]; b = [1;2]; A\b ans = 1.5000