calculate wrong or "/" work different

2 ビュー (過去 30 日間)
pipor
pipor 2023 年 9 月 3 日
コメント済み: Dyuman Joshi 2023 年 9 月 5 日
b=156260
c=165000
c\b
>> untitled3
b =
156260
c =
165000
ans =
0.9470 !?!?!
165000/156260=1.056 i use calc window

採用された回答

Paul
Paul 2023 年 9 月 3 日
編集済み: Paul 2023 年 9 月 3 日
Hi pipor
The ldivide, .\ and mldivide, \, which is what you're actually using here, for the scalar case are mathematically (though not necessarily numerically) the same as
%c\b = (1/c)*b
b=156260;
c=165000;
c\b
ans = 0.9470
(1/c)*b
ans = 0.9470
What you did in the calc window used mrdivide, / which for scalar is the same as rdivide, ./, and does regular old division
c/b
ans = 1.0559
  3 件のコメント
Paul
Paul 2023 年 9 月 3 日
編集済み: Paul 2023 年 9 月 3 日
I'm afraid I don't see the complication. In one case you were basically doing b/c and in the other c/b. For scalar b and c it is true that
b=156260;
c=165000;
b/c
ans = 0.9470
c\b
ans = 0.9470
isequal(b/c,c\b)
ans = logical
1
are equal.
But in the question in the "calc window" you did the reciprocal
c/b
ans = 1.0559
b\c
ans = 1.0559
It all seems consistent and correct.
But do read the doc pages I linked above because there are difrences if b and/or c are non-scalar.
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 5 日
"I don't understand why matlab has to make these complications ..."
These are not complications. Those are different functions with different functionalities.
MATLAB is based on Matrices and both the functionalities have their own significance and use in linear algebra.
Nowhere in Mathematics is forward slash used for division of two numeric values. You, @pipor, yourself used the backward slash to get the result -
%Backward slash
% v
165000/156260=1.056 i use calc window
But why forward slash here?
%v
c\b

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by