The smallest possible value, as described in Modulo Condition MATLAB

I am going to create a function in matlab that will take multiple modulo and their corresponding residuals, then it will determine the smallest possible value that will correspond to the modulo data. The main problem is that I am not allowed to use the built-in mod () and rem () function in matlab. Can you help me?

0
source share
1 answer

You can easily create user-defined functions my_modand my_remwithout the use of modand rem, and you can use them as you would use the modand rem.

function modulus = my_mod(X, Y)
if isequal(Y, 0)
    modulus = X;
elseif isequal(X, Y)
    modulus = 0;
elseif (isequal(abs(X), Inf) || isequal(abs(Y), Inf))
    modulus = NaN;
else
    modulus = X - floor(X./Y) .* Y;
end
return

function remainder = my_rem(X, Y)
if isequal(Y, 0)
    remainder = NaN;
elseif isequal(X, Y)
    remainder = 0;
elseif (isequal(abs(X), Inf) || isequal(abs(Y), Inf))
    remainder = NaN;
else
    remainder = X - fix(X./Y) .* Y;
end
return
+1
source

All Articles