Dividing a number by a column matrix in Matlab

조회 수: 4 (최근 30일)
Duong Cao
Duong Cao 2018년 3월 8일
답변: Aditya 2025년 1월 24일
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