如何计算递归函数的显式形式?
我有这个递归函数:
f(n) = 2 * f(n-1) + 3 * f(n-2) + 4
f(1) = 2
f(2) = 8
我从经验中知道它的明确形式是:
f(n) = 3 ^ n - 1 // pow(3, n) - 1
我想知道是否有任何方法可以证明这一点。我用谷歌搜索了一下,但没有找到任何简单易懂的东西。我已经知道生成函数可能可以解决这个问题,它们太复杂了,我不想深入研究它们。我正在寻找一种更简单的方法。
聚苯乙烯 如果它有帮助,我记得这样的事情解决了它:
f(n) = 2 * f(n-1) + 3 * f(n-2) + 4
// consider f(n) = x ^ n
x ^ n = 2 * x ^ (n-1) + 3 * x ^ (n-2) + 4
然后你以某种方式计算了 x ,导致递归公式的显式形式,但我不太记得
I have this recursive function:
f(n) = 2 * f(n-1) + 3 * f(n-2) + 4
f(1) = 2
f(2) = 8
I know from experience that explicit form of it would be:
f(n) = 3 ^ n - 1 // pow(3, n) - 1
I wanna know if there's any way to prove that. I googled a bit, yet didn't find anything simple to understand. I already know that generation functions probably solve it, they're too complex, I'd rather not get into them. I'm looking for a simpler way.
P.S.
If it helps I remember something like this solved it:
f(n) = 2 * f(n-1) + 3 * f(n-2) + 4
// consider f(n) = x ^ n
x ^ n = 2 * x ^ (n-1) + 3 * x ^ (n-2) + 4
And then you somehow computed x that lead to explicit form of the recursive formula, yet I can't quite remember
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我知道你不想要生成函数(从现在开始)和所有复杂的东西,但我的问题结果是非线性的,简单的线性方法似乎不起作用。经过一整天的搜索,我找到了答案,希望这些发现对其他人有帮助。
我的问题: a[n+1]= a[n]/(1+a[n]) (即不是线性的(也不是多项式),但也不是完全非线性的 - 它是一个有理差分方程)
RSolve[{a[n + 1] == a[n]/(1 + a[n]), a[1] == A}, a[n], n]
给了我一个简单的{{a[n] -> A/(1 - A + A n)}}
。所以我想我会回去寻找手工计算中的错误(它们有助于理解整个转换过程的工作原理)。无论如何,希望这会有所帮助。
Ok, I know you didn't want generating functions (GF from now on) and all the complicated stuff, but my problem turned out to be nonlinear and simple linear methods didn't seem to work. So after a full day of searching, I found the answer and hopefully these findings will be of help to others.
My problem: a[n+1]= a[n]/(1+a[n]) (i.e. not linear (nor polynomial), but also not completely nonlinear - it is a rational difference equation)
RSolve[{a[n + 1] == a[n]/(1 + a[n]), a[1] == A}, a[n], n]
got me a simple{{a[n] -> A/(1 - A + A n)}}
. So I guess I'll go back and look for mistake in hand-calculations (they are good for understanding how the whole conversion process works).Anyways, hope this helps.
一般来说,没有一种算法可以将递归形式转换为迭代形式。这个问题是无法判定的。作为一个例子,考虑这个递归函数定义,它定义了 Collatz 序列:
甚至不知道这是否是一个定义良好的函数。如果存在一种可以将其转换为封闭形式的算法,我们就可以决定它是否定义良好。
然而,对于许多常见情况,可以将递归定义转换为迭代定义。优秀的教科书《具体数学》用了很多篇幅来展示如何做到这一点。当您猜测答案是什么时,一种非常有效的常用技术是使用归纳法。作为您的案例的示例,假设您相信您的递归定义确实给出了 3^n - 1。为了证明这一点,请尝试证明它对于基本情况成立,然后证明这些知识可以让您向上推广解决方案。您没有在帖子中添加基本案例,但我假设
鉴于此,让我们看看您的预感是否正确。对于 0 和 1 的特定输入,您可以通过检查来验证该函数是否计算了 3^n - 1。对于归纳步骤,我们假设对于所有 n' < n f(n) = 3^n - 1。那么我们就得到了
所以我们刚刚证明了这个递归函数确实产生了 3^n - 1。
In general, there is no algorithm for converting a recursive form into an iterative one. This problem is undecidable. As an example, consider this recursive function definition, which defines the Collatz sequence:
It's not known whether or not this is even a well-defined function or not. Were an algorithm to exist that could convert this into a closed-form, we could decide whether or not it was well-defined.
However, for many common cases, it is possible to convert a recursive definition into an iterative one. The excellent textbook Concrete Mathematics spends much of its pages showing how to do this. One common technique that works quite well when you have a guess of what the answer is is to use induction. As an example for your case, suppose that you believe that your recursive definition does indeed give 3^n - 1. To prove this, try proving that it holds true for the base cases, then show that this knowledge lets you generalize the solution upward. You didn't put a base case in your post, but I'm assuming that
Given this, let's see whether your hunch is correct. For the specific inputs of 0 and 1, you can verify by inspection that the function does compute 3^n - 1. For the inductive step, let's assume that for all n' < n that f(n) = 3^n - 1. Then we have that
So we have just proven that this recursive function does indeed produce 3^n - 1.
现在4已经没了。
正如您所说,下一步是让 f(n) = x ^ n
除以 x^(n-2)
因式分解来找到 x
现在使用您求解 A、B 和 C 的值找到
A、B 和 C:
最后
Now the 4 is gone.
As you said the next step is letting f(n) = x ^ n
divide by x^(n-2)
factorise to find x
Now find A,B and C using the values you have
solving for A,B and C:
Finally