필터 지우기
필터 지우기

finding minimum congruent integer

조회 수: 4 (최근 30일)
K G
K G 2016년 2월 20일
편집: John D'Errico 2016년 2월 20일
Hello,
Is there any function that gives the min congruent of an integer?
For example, the congruents of "23 mod 3" are the numbers: 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, ... ( WolframAlpha 's result )
The minimum congruent is 5.
Is there a function that takes as inputs 23 and 3, and gives as output this minimum congruent 5 ?

채택된 답변

John D'Errico
John D'Errico 2016년 2월 20일
편집: John D'Errico 2016년 2월 20일
No. I'm afraid that you are wrong here. The set of numbers that are congruent to 23, modulo 3 are not as you describe, since you missed one (in fact, many) in that list. You forgot to write 2 in the list. Worse, you forgot to include -1, -4, -7, -10, ...
So the "minimum congruent" number that you refer to does not exist, since the set goes on ad infinitum. Infinity is a long way.
Ok, perhaps you wish to know the minimum non-negative number? Trivial. MOD gives that directly.
mod(23,3)
ans =
2
That is indeed the MINIMUM NON-NEGATIVE congruent number to 23, modulo 3.
So, perhaps you really wanted something that you did not say. Perhaps you actually wanted the second smallest (NOT the minimum) positive number that is congruent to 23, modulo 3? Clear explanations of what a person actually wants are so useful sometimes. I'd love to see one in a question, just once. :)
mod(23,3) + 3
ans =
5
Are you asking for a FUNCTION that does it? Ok, a function handle is easiest to write, that takes only one line.
MC = @(N,K) mod(N,K) + K;
MC(23,3)
ans =
5
Or, if you wish to see the entire set of non-negative congruents (I'll need to list only a few, as infinitely many numbers take a while to display)...
mod(23,3) + 3*(0:10)
ans =
2 5 8 11 14 17 20 23 26 29 32
So, whatever you really want, the answer is probably above. I'm just not positive that you are sure that you know what you want. :)
  댓글 수: 1
K G
K G 2016년 2월 20일
I am sorry for the incomplete description, I am indeed looking for the minimum positive congruent.
I 'm also sorry for the misunderstanding of the term "congruent", I am new in this.
Thank you for your answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by