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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by