MATLab help involving Linear Algebra.

65 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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\b instead of inv(A)*b. The command inv(A)*b inverts the matrix $A$ and multiplies $b$ by it, which is not an efficient way to solve a linear system. The command A\b invokes 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:

Warning: Matrix is singular to working precision. 

ans =

   NaN
   NaN
   NaN