对cos x的展开
因为cos ns+i*sin ns=(cos s+i*sin s)^n
cos ns - i*sin ns=(cos s - i*sin s)^n
Go
cos ns =1/2* {(cos s+i*sin s)^n + (cos s - i*sin s)^n}
Go
cos ns 为展开式的偶数项
cos ns=cos s^n +n*(n-1)*cos s^(n-2)*(i*sin s)^2/2!+n*(n-1)*(n-2)*(n-3)*cos s^(n-4)*(i*sin s)
^4/4!.....
Go
设x=n*s ,n很大,s很小,x一般大,n*sin s=n* s=x
cos x=1- x^2/2!+ x^4/4!-x^6/6!....
可以写如下程序进行验证:
(defun pow (num count)
(if (or (> count 1) (eq count 1))
(* num
(pow num
(- count 1) ) )
1)))
(defun expr (i j)
(if (or (eq i (1+ j))(eq j 0) )
1
(+ (expr (- i 1)
j )
(expr (- i 1)
(- j 1) ))))
(defun exprsum (start end xvalue yvalue)
(if (< end 0)
0
(+ (exprsum start (- end 2) xvalue yvalue)
(* (expr start end )
(pow xvalue end )
(pow yvalue (/ (- (1- start)
end )
2))))))
(setq max 20)
(defun test (n)
(if (< n pi)
(progn
(print (exprsum (+ max 1)
max
(cos (/ n
max))
(- 0
(pow
(sin (/ n
max))
2))))
(print 'compare)
(print (cos n))
(test (* n 2)))
(print 'over)))
(test (/ pi 4096))
注意前面为了公式的优美性,采用了假定n是很大的,s是很小的,并且导致n*s=x是为了公式好看,但我们
在这里max的值设置多少都是可以的,是整数就行。
但欧拉的方式能够加快计算出值,收敛程度非常的好。同样可以写程序验证:
(defun slayer (num count)
(if (or (> count 1) (eq count 1))
(* num
(slayer (- num 1)
(- count 1) ) )
1)))
(defun exprsum (n x count)
(if (> n count)
0
(+ (exprsum (+ n 2)
x
count)
(* 1.0
(pow -1
(mod (/ n 2)
2))
(/ (pow x n)
(slayer n n))))))
(defun test (n)
(if (< n pi)
(progn
(print (exprsum 0 n 10))
(print 'compare)
(print (cos n))
(test (* n 2)))
(print 'over)))
(test (/ pi 4096))