Mathematica can solve recursive equations using RSolve. Is it possible to have a function defined by a recurrence, regardless whether the recurrence can or cannot be solved analytically?
-
The recurrence relation is independent of your (or Mma) ability to find a closed form. Could you explain your question further? (please Edit it by clicking here stackoverflow.com/posts/5702431/edit)Dr. belisarius– Dr. belisarius2011-04-18 11:56:21 +00:00Commented Apr 18, 2011 at 11:56
Add a comment
|
2 Answers
Yes. Look at RecurrenceTable. One also can program to define a function by its recurrence equation, factorial being the simplest example.
In[94]:= fac[1] = 1;
fac[k_Integer?Positive] := k*fac[k - 1]
In[96]:= fac[10]
Out[96]= 3628800
In[97]:= Function[If[#1 == 1, 1, #1*#0[#1 - 1]]][10]
Out[97]= 3628800
In[100]:= RecurrenceTable[
f[k] == k f[k - 1] && f[1] == 1, f, {k, 1, 10}]
Out[100]= {1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800}
4 Comments
Dr. belisarius
@rcollyer @Sasha I fail to see the point in the question (I commented about that there), and also in the answer. The three formulations are the same (as I see it), as you may convert from one to the other. So ... what is the question trying to find out? Just curious ...
Sasha
@belisarius I guess @malina was looking for an example that defines a function by its recurrence equation, and this is what the answer provided. I should have probably provided more educational links. I agree, neither the question nor the answer are particularly useful for the community at large being too basic.
rcollyer
@belisarius, I agree to some extent; I was just trying to provide more insight into a confusing bit of notation. But, I disagree that the three examples are the same. While they are capable of giving the same result, they do so via different notations and
RecurrenceTable may operate very differently than the others. On that alone, the answer is useful; the question, however, I don't know.I wondered for a moment what RecurrenceTable is good for, until I rewrote Sasha's example using NestList:
Rest@NestList[{1, 0} + First@# {1, Last@#} &, {1, 1}, 10][[All, -1]]
{1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800}
If the involvement of k (First@#) is complicated, RecurrenceTable could be far simpler.