How to evaluate recursive piecewise symbolic functions?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Is it possible to define & evaluate recursive piecewise symbolic functions. As a simple example, here's an attempt at a recursive factorial symbolic function:
syms f(n)
syms fn(n)
f(n)=n
fn(n)=piecewise(n==1,1,n>1,f(n)*fn(n-1))
However, when calling it:
fn(4)
There's no recursion in the evaluation. Although f(n) is evaluated, fn(n-1) isn't:
ans=4 fn(3)
I know in this case I could do fn(n)=factorial(n) to get the correct answer, but this is just a simpler version of the recursive function I'm trying to code. Thanks.
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Assumptions in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!