필터 지우기
필터 지우기

Cannot find where I am hitting recursion limit

조회 수: 1 (최근 30일)
Tony
Tony 2015년 8월 24일
댓글: Sean de Wolski 2015년 8월 26일
Hi, matlab continues to tell me that I am getting a recursion limit problem with this code and I can't seem to see where my code is over doing itself. If you could help, that would be great. For me, I used k = 19 and received the problem. Please note that the function phi(k) is not where the issue is coming from
function PR(k)
function out = phi(k)
out = phi(k);
end
if k > 1 && rem(k,1)==0
for i = 1:k
if rem(k,i)==0
y(i) = k./i;
else
y(i) = 1;
end
end
for m = 1:k
z(m) = mod(y(m).^y(m),k);
if mod(z(m)-1,phi(k))==0
w(m) = z(m);
else
w(m) = 1;
end
end
else
disp('Please make sure your input is an integer greater than 1');
end
end

답변 (1개)

Sean de Wolski
Sean de Wolski 2015년 8월 24일
편집: Sean de Wolski 2015년 8월 24일
The issue is indeed from calling phi(k)
function out = phi(k)
out = phi(k);
end
Calls itself infinitely and causes the recursion error.
%
  댓글 수: 2
Tony
Tony 2015년 8월 25일
Since the function ends though, why does it keep calling itself? Like, shouldn't the code begin, enter the function that calls phi, generate an output, end, then continue with rest of code?
Sean de Wolski
Sean de Wolski 2015년 8월 26일
It never gets to the end. It calls phi, i.e. itself, again and then jumps back into itself on the next iteration once again calling itself before reaching the end.
What do you actually want phi to do?

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

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by