Please answer the following question in MATLAB and include well detailed comment
ID: 3818473 • Letter: P
Question
Please answer the following question in MATLAB and include well detailed comments so that I can understand all functions and processes. Please read instructions carefully and implement in beginner MATLAB code. Thanks in advance.
3. Congruence (30 points) Implement a function called Congruent which returns True if a E b (mod m meaning a is congruent to b (mod m) else it returns False. The condition for it to be true is when a (mod m) b mod m The funtion takes only 3 input parameters a,b and m. The function should ensure that m is a positive integer. Give two test examples that returns True and two that returns False.Explanation / Answer
function [output] = Congruent(a, b, m) %output indicates the variable name the function returns
output = false; % we initiate output to false
if m > 0 % we here check if m is +ve num, if not it does not enter the loop
x = mod(a,m); % we find the mod or remainder for a and m
y = mod(b,m); % we then find the mod or remainder for b and m
if x == y % we check if both the remainder are same, if equal. we change the value of output
output = true; % if the remainders are not equal, output remains false
end %end of if x == y
end %end of if m > 0
end % end of function, we do not have to return value explicitly
OUTPUT:
>Congruent(5, 7, 2)
> 1
>Congruent(4, 7, 3)
> 1
>Congruent(5, 7, -1)
> 0
>Congruent(5, 8, 4)
> 0