In general if 2 is divided by 10 then the answer is 0.2 and the remainder is 0.0. but MATLAB shows the remainder is 2.0.... why?

Answers (1)

Because that is how the standard definition of the modulo operation works, and MATLAB's rem and mod functions both implement this correctly. Because that is what the remainder is.
Here are some links that will help understand this:
And please make a formal complaint to your middle school that they are not doing their job properly.

2 Comments

@Khan Mohaimanul Islam: I presume this email was from you:
"thank you for answering my question. but i have found the conventional rule, those i know already. but how 2/10 gives remainder 2?"
Because 2/10 is not the same operation as rem(2,10), which you would already know if you had actually taken the time to read any of the links that I gave in my answer. The rem documentation clearly states: " rem(X,Y) returns X - n.*Y, where n = fix(X./Y)". Note that this is not the same as X/Y, as you presume it to be. Now lets try some values using the algorithm given in the documentation:
>> X = 2;
>> Y = 10;
>> n = fix(X./Y)
n =
0
>> X - n.*Y
ans =
2
Summary: X./Y is not the same as rem(X,Y).
Isn't this actually the first kind of division that they teach you in primary school anymore?
I want to put my 2 apples in bags of 10. How many bags do I fill exactly and how many apples are left over?
I fill 0 bags fix(2/10) and am left over with 2 apples rem(2, 10)

Sign in to comment.

Categories

Find more on Linear Algebra in Help Center and File Exchange

Asked:

on 11 Jul 2015

Edited:

on 28 Aug 2015

Community Treasure Hunt

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

Start Hunting!