フィルターのクリア

Calculation of Factorial using Recursive Relation

1 回表示 (過去 30 日間)
onsagerian
onsagerian 2018 年 7 月 31 日
コメント済み: onsagerian 2018 年 8 月 13 日
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

採用された回答

James Tursa
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 件のコメント
onsagerian
onsagerian 2018 年 8 月 13 日
Thank you for your explanation!

サインインしてコメントする。

その他の回答 (1 件)

Jeff Miller
Jeff Miller 2018 年 8 月 1 日
This might help: Wikipedia

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by