Effacer les filtres
Effacer les filtres

Calculation of Factorial using Recursive Relation

1 vue (au cours des 30 derniers jours)
onsagerian
onsagerian le 31 Juil 2018
Commenté : onsagerian le 13 Août 2018
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

Réponse acceptée

James Tursa
James Tursa le 1 Août 2018
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 commentaire
onsagerian
onsagerian le 13 Août 2018
Thank you for your explanation!

Connectez-vous pour commenter.

Plus de réponses (1)

Jeff Miller
Jeff Miller le 1 Août 2018
This might help: Wikipedia

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by