基础对数级数公式展开的来源(实践)
前面描述过,对于自然对数的底e而言,有如下公式成立,下面尝试着写程序,严整当x取不同的值时候,两者是否真的相等;
log (1+x)={ 1*x^1/1!-1*x^2/2+ 1*x^3/3-1*x^4/4 ...}
下面写程序来证明:
(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 value)
(if (eq n 1)
value
(+ (expr (1- n)
value)
(* (pow -1
(1+ n))
(pow value
n)
(/ 1.0
n)))))
(defun test (n)
(if (> n 0)
(progn
(print (expr n
(/ 1.0
n)))
(print 'compare)
(print (log (+ 1
(/ 1.0
n))))
(test (- n 1)))
(print 'over)))
(test 20)
n的值越大,两者的值越吻合。
[8]> (test 20)
0.048790168
COMPARE
0.04879012
0.051293295
COMPARE
0.05129333
0.054067224
COMPARE
0.054067247
0.057158418
COMPARE
0.057158466
0.060624618
COMPARE
0.06062462
0.064538516
COMPARE
0.064538576
0.068992876
COMPARE
0.06899284
0.07410797
COMPARE
0.07410803
0.08004272
COMPARE
0.08004274
0.087011375
COMPARE
0.087011404
0.09531018
COMPARE
0.095310204
0.10536052
COMPARE
0.10536056
0.11778303
COMPARE
0.11778303
0.13353144
COMPARE
0.13353144
0.15415023
COMPARE
0.15415065
0.18233067
COMPARE
0.1823216
0.22298177
COMPARE
0.22314355
0.29012346
COMPARE
0.28768212
0.375
COMPARE
0.4054651
1.0
COMPARE
0.6931472
OVER
OVER