I am trying to understand what is happening here..
A = floor(10*rand(3));
b = sum(A')';
z = ones(3,1);
If I solve the system $Ax = b$, the solution is identical to the z vector..
I take inv(A) * b $=$ a column vector of ones, which is equivalent to what z outputs.
What is the reason for this? I am new to MATLab and Linear Algebra.
The answer was given in comments: your $b$ is the same as $Az$, so it's no surprise you get $z$ as the solution.
Practical remark: use
A\binstead ofinv(A)*b. The commandinv(A)*binverts the matrix $A$ and multiplies $b$ by it, which is not an efficient way to solve a linear system. The commandA\binvokes an efficient built-in solver, which employs some adaptive algorithm to produce the solution.Also, your code will sometimes produce an output different from $z$. Namely, when the random matrix $A$ happens to be singular: