How to solve for the analytic solution of a recurrence relation in mathematica

时光毁灭记忆、已成空白 提交于 2019-12-07 16:58:00

问题


I have a recurrence such as following:

RSolve[{f[m, n] == f[m, n - 1] + f[m - 1, n], 
        f[0, n] == 1, f[m, 0] == 1}, 
        f[m, n], {n}]

I tried to use RSolve, but I got an error:

RSolve::deqx: Supplied equations are not difference equations 
              of the given functions.

Appreciate your help!


回答1:


The difference equation and initial conditions are

Mathematica (7 and 8) does not like solving it... both with and without initial conditions. The RSolve expressions are left unevaluated

In[1]:= RSolve[{f[m,n]==f[m,n-1]+f[m-1,n],f[0,n]==f[m,0]==1},f[m,n],{m,n}]
        RSolve[{f[m,n]==f[m,n-1]+f[m-1,n]},f[m,n],{m,n}]
Out[1]= RSolve[{f[m,n]==f[-1+m,n]+f[m,-1+n],f[0,n]==f[m,0]==1},f[m,n],{m,n}]
Out[2]= RSolve[{f[m,n]==f[-1+m,n]+f[m,-1+n]},f[m,n],{m,n}]

I know that Mathematica uses generating functional methods (probably among other things) to solve such recurrences, but I don't know why it fails in such a simple case.

So let's do it by hand.

Let g(x,n) be the generating function for f(m,n)

Now examine the sum of f(m+1,n) x^m

Now solve the simple algebraic-difference equation:

Which can also be done with RSolve

In[3]:= RSolve[g[x,n]-x g[x,n]==g[x,n-1]&&g[x,0]==1/(1-x),g[x,n],n];
        Simplify[%,Element[n,Integers]]
Out[4]= {{g[x,n]->(1-x)^(-1-n)}}

Now extract the coefficient of x^m:

In[5]:= SeriesCoefficient[(1 - x)^(-1 - n), {x, 0, m}]
Out[5]= Piecewise[{{(-1)^m*Binomial[-1 - n, m], m >= 0}}, 0]

The binomial is simplified using

In[6]:= FullSimplify[(-1)^m*Binomial[-n - 1, m] == Binomial[m + n, m], Element[{n,m}, Integers]&&m>0&&n>0 ]
Out[6]= True

So we finally get

This can be checked using symbolic and numeric means

In[7]:= ff[m_,n_]:=ff[m,n]=ff[m-1,n]+ff[m,n-1]
        ff[0,_]:=1;ff[_,0]:=1
In[9]:= And@@Flatten[Table[ff[m,n]==Binomial[n+m,m],{n,0,20},{m,0,20}]]
Out[9]= True

In[10]:= {f[m,n]==f[m,n-1]+f[m-1,n],f[0,n]==f[m,0]==1}/.f->(Binomial[#1+#2,#1]&)//FullSimplify
Out[10]= {True,True}



回答2:


Not the answer but it seems that the right form should be (note {m, n} at the end):

RSolve[{f[m, n] == f[m, n - 1] + f[m - 1, n], f[0, n] == 1, f[m, 0] == 1}, f[m, n], {m, n}]

Mathematica leaves this unevaluated. I think it just cannot solve this.



来源:https://stackoverflow.com/questions/4940572/how-to-solve-for-the-analytic-solution-of-a-recurrence-relation-in-mathematica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!