Inaccuracy when using 'mrdivide' and backslash '/' for Solving xA=b

4 views (last 30 days)
Hi everyone I would like to solve the equation xA=b where:
b=
0 21.8182 0 -7.2727
1.6154 -4.8462 -0.5385 1.6154
2.4000 -12.0000 -0.8000 4.0000
-0.8824 0.2941 0.2941 -0.0980
0.6000 1.0909 0 0
0.0814 0.1407 0 0
A=
-3 0 1 0
0 -3 0 1
Since both the b and A matrices have the same number of columns, I use the backlash '/' function in Matlab as follows:
x=b/A;
Which returns the following value of x
0 -7.2727
-0.5385 1.6154
-0.8000 4.0000
0.2941 -0.0980
-0.1800 -0.3273
-0.0244 -0.0422
However when I multiply this value of x with A, instead of getting the matrix 'b' I get the following result which is identical to 'b' fo the first four columns but is totally inaccurate for the last two columns : xA=
0 21.8182 0 -7.2727
1.6154 -4.8462 -0.5385 1.6154
2.4000 -12.0000 -0.8000 4.0000
-0.8824 0.2941 0.2941 -0.0980
0.5400 0.9818 -0.1800 -0.3273
0.0733 0.1266 -0.0244 -0.0422
I think I must be missing something theoretically, please do guide me on how I can rectify this inaccuracy..Thanks!
  1 Comment
John D'Errico
John D'Errico on 20 May 2015
No. You are NOT using backslash. You are using FORWARDslash. There is a difference, although some might call it subtle.

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 20 May 2015
Edited: John D'Errico on 20 May 2015
You CANNOT "rectify" the inaccuracy. The problem is in your understanding of linear algebra. You can only recognize (and accept) that not all things are mathematically possible.
There is simply NO solution to the problem for all cases. Lets look at what you are trying to do. When solving the linear system x*A = b, our goal is to find a linear combination of the ROWS of A, that will yield a given row of b.
A= [-3 0 1 0;
0 -3 0 1];
b= [0 21.8182 0 -7.2727;
1.6154 -4.8462 -0.5385 1.6154;
2.4000 -12.0000 -0.8000 4.0000;
-0.8824 0.2941 0.2941 -0.0980;
0.6000 1.0909 0 0;
0.0814 0.1407 0 0]
Lets solve for ONE row of b at a time, and see what happened, because each row of b is essentially a completely different problem.
x = b(1,:)/A
x =
0 -7.2727
x*A
ans =
0 21.818 0 -7.2727
What does it mean to multiply A on the left by a row vector x? Essentially, this takes a linear combination of the rows of A. So 0 times the first row, plus -7.2797 times the second row. As you can see, that yields exactly the first row of b.
However, this is a 4 dimensional problem, in that b has 4 columns. So essentially there are 4 variables. Had A been the matrix (eye(4)) then it is true that we can always find SOME linear combination of the rows of A for ANY row of B. But A has only TWO rows. So there are some linear combinations that we simply cannot reach, no matter how much you want it. Mathematics is unforgiving in that sense. When something is mathematically impossible, it is exactly that - IMPOSSIBLE.
So there exist linear combinations of the rows of A that will yield the first four rows of b. No problems there.
But think about it for the last two rows of b. Look at those last two columns.
b(5:6,:)
ans =
0.6 1.0909 0 0
0.0814 0.1407 0 0
Now, look back at A. A has a 2x2 identity matrix in those last two columns. What linear combination of those rows will give EXACTLY zero in the last two columns? There simply is NO non-zero linear combination of the rows of A that will yield zeros in those last two columns of the result. Sorry, but it is not possible. Period. The best that can be done is what you see...
x = b(5:6,:)/A
x =
-0.18 -0.32727
-0.02442 -0.04221
x*A
ans =
0.54 0.98181 -0.18 -0.32727
0.07326 0.12663 -0.02442 -0.04221
This is as close as you can come, in a least squares sense, to solving the problem.
  1 Comment
Ahmad
Ahmad on 24 May 2015
Thank you very much for this detailed and very helpful explanation. I will revise my Linear Algebra course notes and always check the theoretical aspects of the problem before applying them to Matlab

Sign in to comment.

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!