Understanding Matrix Division in Matlab: Solving Linear Systems

Click For Summary
SUMMARY

This discussion clarifies the use of the backslash operator in MATLAB for solving linear systems represented by the equation Ax = b. The correct command to find x is x = A\b, which utilizes MATLAB's efficient mldivide function to compute the solution. The discussion emphasizes that matrix division is not commutative, meaning that x = b/A is a different operation and yields different results. Understanding the distinction between the forward-slash and backslash operators is crucial for correctly solving linear equations in MATLAB.

PREREQUISITES
  • Familiarity with linear algebra concepts, particularly matrix operations.
  • Basic understanding of MATLAB syntax and commands.
  • Knowledge of the mldivide and mrdivide functions in MATLAB.
  • Experience with matrix multiplication and its non-commutative properties.
NEXT STEPS
  • Research the mldivide function in MATLAB for efficient linear equation solving.
  • Learn about the properties of matrix multiplication and its implications in linear algebra.
  • Explore the mrdivide function in MATLAB for solving equations in the form xA = b.
  • Study examples of non-commutative operations in matrix algebra to deepen understanding.
USEFUL FOR

Mathematicians, engineers, and data scientists who utilize MATLAB for solving linear systems and anyone looking to enhance their understanding of matrix operations in programming.

gfd43tg
Gold Member
Messages
949
Reaction score
48
Hello, I am confused about a concept,

Suppose I am trying to solve a linear system ##Ax = b##

I want to know why is it when I solve for x, the command is x = A\b. Why would it not be x = b\A. One could see that if you divide x on both sides, then b/x = A. Is this not true for the matrix?
 
Physics news on Phys.org
The correct operation is:
##x=A^{-1}b##

The "A\" notation tells MATLAB to make the inverse of A and apply it to the following vector, using an efficient process coded into the m-file. It's just a notation.

Division, like you did with b/x, is not defined for vectors and matrixes - which you should be able to tell by experimenting with a few examples.

Code:
octave:41> A=magic(3)
A =

   8   1   6
   3   5   7
   4   9   2

octave:42> x=[1,2,3]'
x =

   1
   2
   3

octave:43> b=A*x
b =

   28
   34
   28

octave:44> b/x
ans =

   2.0000   4.0000   6.0000
   2.4286   4.8571   7.2857
   2.0000   4.0000   6.0000
... clearly A≠b/x
(Also try this by hand.)

You should understand that MATLAB is a computer program which implements commands according to it's own internal logic. The full answer to your question is in how MATLAB interprets the forward-slash and backslash characters.

See discussion:
http://scicomp.stackexchange.com/qu...slash-operator-solve-ax-b-for-square-matrices
 
Last edited:
Matrix multiplication is not always commutative, like it is with scalars. So you can take for granted the fact that 5*3 = 3*5 = 15. But if you have something like the following it's different:

Code:
A = [1 2; 3 5];
B = [1 -1; -1 1];
A*B

ans =

    -1     1
    -2     2

B*A

ans =

    -2    -3
     2     3

So ultimately this means that solving Ax = b and solving xA = b are two different problems.

If you solve Ax = b, you get x = A^{-1}b. Notice that A is on the left in each case.
If you solve xA = b, you get x = bA^{-1}, and, as I just mentioned, this can be different from the form above. Here A is on the right.

So, we have two different problems requiring 2 different operators.

To solve Ax = b, you use x = A\b. That is, if A is on the left, use mldivide \.
To solve xA = b, you use x = b/A. If A is on the right, use mrdivide /.

(For more info, see http://blogs.mathworks.com/cleve/2013/08/19/backslash/ )

MATLAB solves these equations quite efficiently depending on the properties of the coefficient matrix, A. A description of the algorithm is here at the bottom of the page: http://www.mathworks.com/help/matlab/ref/mldivide.html
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K