backslash(\) is through error in 2013a but not to 2018b

조회 수: 1 (최근 30일)
Murugan C
Murugan C 2023년 4월 19일
댓글: Murugan C 2023년 4월 20일
the below syntax is working in matlab 2018b
s = [1 2 3 4; 5 6 7 9; 1 1 1 1 ; 1 1 1 1];
b=[1;1;1;1];
d = s.\b
%%result
d =
1.0000 0.5000 0.3333 0.2500
0.2000 0.1667 0.1429 0.1111
1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000
but in 2013a is throug "Matrix dimensions must agree."
may i know why?
Thanks in advance
Murugan

채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 19일
You did not use the \ operator: you used the .\ operator.
A.\B is the same as B./A -- element-wise division but with the order of operands reversed from the usual element-wise division.
The .\ operator is obscure, and I have never found a reason to use it other than for testing.
The reason the operator works on newer versions but fails on older versions is that you are doing element-by-element division between two arrays the same size. R2015b added the feature of "implicit expansion": for the element-by-element binary operators between two arrays, if the two arrays are the same size except that one might have size 1 in a dimension that the other is not 1, then the array with size 1 for the dimension will be automatically replicated to be the same size as the other.
Now, if you had used d = s\b with the \ operator instead of the .\ operator, then you would have had proper array sizes for the matrix-left-divide operator even back in R2013 time frame.
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 4월 19일
What calculation are you trying to perform?
The last two rows of s are the same, so s cannot possibly be full rank, so if you were hoping to do least-squared fitting or trying to solve s*x = b then you will not be able to do so.
Murugan C
Murugan C 2023년 4월 20일
i got your point. thanks.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by