Why does the MOD function from the Math Function block return unexpected results with negative inputs in Simulink?
16 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2009 年 6 月 27 日
編集済み: MathWorks Support Team
2021 年 6 月 20 日
Why does the MOD function from the Math Function block return unexpected results with negative inputs in Simulink?
I have a model with a MOD block. The inputs to the block are two constant values, for example -10 and 100. The output of the block is 90. I would have expected the result to be 10. Why is 90 returned?
採用された回答
MathWorks Support Team
2021 年 6 月 20 日
編集済み: MathWorks Support Team
2021 年 6 月 20 日
The results returned from the Simulink MOD function are consistent with the MATLAB MOD function and the description from the help:
MOD(x,y) is x - n.*y
where n = floor(x./y) if y ~= 0.
As a workaround, you can use the REM function in the Math Function block. As long as the operands X and Y are of the same sign, the function mod(X,Y) returns the same result as does rem(X,Y). However, for positive X and Y, mod(-X,Y) = rem(-X,Y)+Y.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Simulink Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!