How parentheses effects multiplication with pi ?
古いコメントを表示
Hi,
I am trying to generate sine wave. I am usning following two code lines. But they are slightly different (about e-15). Why is it happenning ? What is the differences of two lines;
f0=5e2;
fs=500e2;
len=3e3;
dt=1/fs;
t=0:dt:(len-1);
sing1= sin (2*pi*f0*t);
sing2= sin(2*pi*(f0*t));
isequal(sing1,sing2)
Thanks for your help,
採用された回答
その他の回答 (1 件)
madhan ravi
2020 年 8 月 4 日
0 投票
In the first the order of operation is from left to right.
In the second the order of operation is inside the parenthesis and then the outer.
7 件のコメント
madhan ravi
2020 年 8 月 4 日
BODMAS
Emre Doruk
2020 年 8 月 5 日
madhan ravi
2020 年 8 月 5 日
編集済み: madhan ravi
2020 年 8 月 5 日
Click on the tag floating-point. And read my answer once again.
Emre Doruk
2020 年 8 月 5 日
"Because it is the same oparetaion, left to right or the right to left. "
No, that is incorrect.
In general operations on binary floating point numbers are NOT associative:
A classic example of this is called catastrophic cancelation:
>> (1 + 1e100) - 1e100
ans =
0
>> 1 + (1e100 - 1e100)
ans =
1
"Why is it happenning?"
Because of the well-documented properties of binary floating point numbers.
Emre Doruk
2020 年 8 月 5 日
madhan ravi
2020 年 8 月 5 日
Thanks Stephen:)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!