等差数列中非齐次等比函数项的消除2
//测试如下函数a(n)=2*a(n-1)+3^n
//通过1的分析X=A*2^n+B*3^n
GO
2*A+3*B=2
4*A+9*B=13
GO
A=-7/2
B=3
(defun pow (num count)
(if (> count 0)
(* num (pow num (- count 1) ) )
1
)
)
(defun expr (n)
(if (eq n 1)
2
(+ (* 2 (expr (- n 1) ) )
(pow 3 n))))
(setq A (- 0 (/ 7 2.0)))
(setq B 3.0 )
(defun formula (n)
(+ (* A (pow 2 n))
(* B (pow 3 n))))
(defun test (n)
(if (> n 0)
(progn
(print (formula n))
(print (expr n))
(test (- n 1) ))
(print 'over)))
(test 10)