Why is 1/ones(3,1) OK while 1/ones(1,3) is not OK?

조회 수: 2 (최근 30일)
Yuki Koyama
Yuki Koyama 2019년 9월 19일
편집: David Goodmanson 2019년 9월 20일
When I tried the code
1/ones(1,3)
matlab said this is invalid because the dimension is not matched.
Then I tried the code
1/ones(3,1)
this returns the result
ans =
1 0 0
I don't know why the ans is like this.
  댓글 수: 1
Stephen23
Stephen23 2019년 9월 19일
편집: Stephen23 2019년 9월 19일
"I don't know why the ans is like this."
Did you read the mrdivide documentation, to know what you are actually calculating?:

댓글을 달려면 로그인하십시오.

채택된 답변

David Goodmanson
David Goodmanson 2019년 9월 19일
편집: David Goodmanson 2019년 9월 20일
Hi Yuki,
In the expression x = 1/ones(3,1) multiplying both sides on the right by ones(3,1) gives
x*ones(3,1) = 1.
The row vector x = [1 0 0] fills the bill, since
[1 0 0] x [1
1 = 1.
1]
Note that the answer is not unique, since
x = [0 1 0], x = [1/3 1/3 1/3] etc. all work just as well.
As to why ones(1,3) errors out, in that case you would have
x*ones(1,3) = 1.
If you review the rule for sizes of rows and columns in matrix multiplication, i.e. (mxn) x (nxq) = mxq, you will find that the eqn above does not work.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by