Pregunta

I have a question about how the rem() function works in Matlab.

I have a sample code but I don't have Matlab to run it. So, I was studying the Matlab function reference page. However, I don't really understand how rem() function is working.

First, how rem() function work? For example, if rem(5,0.1) then what should I get as value?

Second, does rem function handle 2x2 arrays? For example, I have an 2x2 array a and a 2x2 array b, can I do rem(a,b)?

¿Fue útil?

Solución

The function rem() calculates the remainder after division. In the equation a = qd + r, the number q is the quotient and r is the remainder. The quotient q is a natural number, i.e. 0,1,2,3, etc, while the remainder r is in the range 0<=r<d. When you call the function rem(a,d), it evaluates this expression a-qd<d for all the natural numbers. When the condition is satisfied, it is output: r=a-qd.

The arguments can be single numbers, arrays or matrices. For example, if you execute:

a = rem(0:10,3);
b = rem(0:10,4);
c = rem([1 2; 3 4],[4 3; 2 1]);
d = rem(5, 0.1);
e = rem(0.05, 0.1);

You get:

a = [0 1 2 0 1 2 0 1 2 0 1];
b = [0 1 2 3 0 1 2 3 0 1 2];
c = [1 2;1 0];
d = 0;
e = 0.05;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top