Calculation of Factorial using Recursive Relation
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have tried to construct a code using a "function" that contains a "recursive relation", but was not able to complete it. The following Matlab code is designed to compute 10!. Would you help me to find out the solution?
n=10;
f=@recursion; <===?
function y=recursion(n)
y=n*recursion(n)
end
댓글 수: 0
채택된 답변
James Tursa
2018년 8월 1일
You need the proper formula first:
y = n * recursion(n-1);
But also you need to figure out how to stop the recursion and simply return a number. I will let you work that out.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Software Development Tools에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!