recursion-Arkermann function- code run but have wrong answer
2 views (last 30 days)
Show older comments
The Ackermann function, A, is a quickly growing function that is defined by the recursive relationship: A(m, n) = n +1 if m = 0; A(m − 1, 1) if m > 0 and n = 1; A(m − 1, A(m, n − 1)) if m > 0 and n > 0 Write a function with header [A] = myAckermann(m,n), where A is the Ackermann function computed for m and n. // My code run but it give wrong result , can you help me correct ?
if true
% code
end
function [A]= myAckermann(m,n)
%--------------------------------------------------------------------------
% recursion
%A(m,n) = n+1 if m=0
%A(m,n) = A(m-1,1) if m>0 and n=1
%A(m-1,A(m,n-1)) if m>0 and n>0
%Tho Huynh
%9/8/2016
%-------------------------------------------------------------------------
if m==0
A = n+1;
elseif m>0 && n==1
A= myAckermann(m-1,1);
else m>0 && n>0
A= myAckermann(m-1,myAckermann(m,n-1));
end
end
if true
% code
end
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!