Dividing a number by a column matrix in Matlab

2 次查看(过去 30 天)
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 ?

回答(1 个)

Aditya
Aditya 2025-1-24
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:

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by