2014-11-04 70 views
1

在matlab中是否存在相當於c#方法Math.IEEERemainder的方法。有關此方法c#方法Math.IEEERemainder(x,y)在MATLAB中等價嗎?

詳細信息可以在這裏找到:Is Math.IEEERemainder(x,y) equivalent to x%y?

根據IEEERemainder規格:

3/2 should be -1 

然而Matlab的方法mod(3,2)返回1和rem(3,2)也返回1

+0

你見過['mod'(http://www.mathworks.com/help/matlab/ref/mod.html)和['REM '](http://www.mathworks.com/help/matlab/ref/rem.html)在MATLAB中?也值得一讀[計算機科學家分部和模數](http://research.microsoft.com/pubs/151917/divmodnote.pdf) – Amro 2014-11-04 14:43:02

回答

1

正確的數學函數將是x-y*round(x/y)。該表達式與Math.IEEERemainder之間的唯一區別在於x/y的值恰好在兩個整數之間的中途。在那種情況下,round(x/y)從零開始舍入,而在Math.IEEERemainder的舍入函數舍入爲偶數。

函數可以是這樣的:

function out=IEEERemainder(x,y) 
x-y.*round(x./y) 
end 
+1

我不認爲這是相當於'Math.IEEERemainder'在C# – Amro 2014-11-04 14:49:23

+0

你對了。我誤解了rem(x,y)的幫助。我認爲我的編輯是正確的。 – ScheissSchiesser 2014-11-04 15:07:19

+0

它的工作原理應該如此。但是,我不知道是否有內置的matlab方法。 – User1551892 2014-11-04 15:11:27