用母函数证明一个以前用积分法证明的公式
求数列1+2*x+3*x^2+....
从这里可以看出系数的差分方程为a(n)-2*a(n-1)+a(n-2)=0
即为x^2-2*x+1=0
从而可以设置它的和为A/(1-x+x^2)=1+2*x+3*x^2+....
用带定系数法可以解得A=1,
下面写程序验证:
(defun pow (num count)
(if (or (> count 1) (eq count 1) )
(* num
(pow num
(- count 1) ) )
1))
(defun slayer ( count)
(if (or (> count 1) (eq count 1) )
(* count
(slayer
(- count 1) ) )
1))
(defun expr (n x)
(if (eq n 1)
1.0
(+ (expr (1- n)
x)
(* n
(pow x
(1- n)))))))
(defun formula (x)
(/ 1.0
(pow (1- x)
2)))
(defun test (n)
(if (> n 0)
(progn
(print (expr n 0.9))
(print 'compare)
(print (formula 0.9))
(test (- n 1)))
(print 'over)))
(test 300)
n越大值越对。