Dividing a number by a column matrix in Matlab

3 views (last 30 days)
Duong Cao
Duong Cao on 8 Mar 2018
Answered: Aditya on 24 Jan 2025
For example if I were to type this in matlab: >> 1/[1, 2 ,3] There would be an error: >> Error using / Matrix dimensions must agree.
But if I were to type this in Matlab >> 1/[1; 2; 3] The answer would be: [0 0 0.3333]
Why is Matlab doing this ?

Answers (1)

Aditya
Aditya on 24 Jan 2025
Hi Duong Cao,
Here's an explanation of this behavior that you're observing:
1] Matrix Division Error:
  • When you try 1/[1, 2, 3], MATLAB attempts to perform matrix right division. Here, it interprets the operation as solving the equation x * [1, 2, 3] = 1 for x. This requires the dimensions to be compatible for matrix multiplication, which isn't possible because a scalar (1x1) cannot multiply a row vector (1x3) to produce a scalar (1x1). Hence, you encounter a dimension mismatch error.
2] Pseudo-Inverse Solution:
  • When you use 1/[1; 2; 3], MATLAB interprets this as multiplying 1 by the pseudo-inverse of the column vector [1; 2; 3]. This is a valid operation because the pseudo-inverse provides a way to handle non-square matrices, resulting in a least-squares solution. In this case, it returns [0, 0, 0.3333], which satisfies the equation in a least-squares sense.
For more detailed information, you can refer to the MATLAB documentation on matrix right division:
Additionally, you may find this MATLAB Central answer post helpful, as it discusses a similar case:

Categories

Find more on Operating on Diagonal Matrices 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!