泰勒公式求正余弦

正弦

sinx=x-x^3/3!+x^5/5!-.....+(-1)^(m-1)*x^(2*m-1)/(2*m-1)!

# _*_ coding:utf-8 _*_

import numpy as np

def jie(i):
    s = 1
    for j in range(1, i+1):
        s = s * j
    return s

if __name__ == '__main__':
    x = int(input("请输入x="))
    n = int(input("请输入n="))
    s = 0
    for i in range(1, n+1):
        s = s + np.power(-1, i-1) * np.power(x, 2*i-1)/jie(i*2-1)
    #print(np.sin(x))
    print(s)

余弦

cosx=1-x^2/x!+x^4/4!-.......+(-1)^m*x^(2*m)/(2*m)!

# _*_ coding:utf-8 _*_

import numpy as np

def jie(i):
    s = 1
    for j in range(1, i+1):
        s = s * j
    return s

if __name__ == '__main__':
    x = int(input("请输入x="))
    n = int(input("请输入n="))
    s = 1
    for i in range(1, n+1):
        s = s + np.power(-1, i) * np.power(x, 2*i)/jie(i*2)
    #print(np.cos(x))
    print(s)

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013589137/article/details/79950144
个人分类: 数学
上一篇泰勒公式求 e的x次方
下一篇汇编 改大写
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭