How to evaluate recursive piecewise symbolic functions?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!