我是靠谱客的博主 虚心未来,这篇文章主要介绍怎样使用python画复杂函数_如何用python画常值函数?,现在分享给大家,希望可以做个参考。

你好。

import numpy as np

import math

import matplotlib as mpl

import matplotlib.pyplot as plt

def calc_e_small(x):

n = 10

f = np.arange(1, n+1).cumprod()

b = np.array([x]*n).cumprod()

return np.sum(b / f) + 1

def calc_e(x):

reverse = False

if x < 0: # 处理负数

x = -x

reverse = True

ln2 = 0.69314718055994530941723212145818

c = x / ln2

a = int(c+0.5)

b = x - a*ln2

y = (2 * a) calc_e_small(b)

if reverse:

return 1/y

return y

if name == "main":

t1 = np.linspace(-2, 0, 10, endpoint=False)

t2 = np.linspace(0, 3, 20)

t = np.concatenate((t1, t2))

print(t) # 横轴数据

y = np.empty_like(t)

for i, x in enumerate(t):

y[i] = calc_e(x)

print('e^', x, ' = ', y[i], '(近似值)t', math.exp(x), '(真实值)')

print '误差:', y[i] - math.exp(x)

最后

以上就是虚心未来最近收集整理的关于怎样使用python画复杂函数_如何用python画常值函数?的全部内容,更多相关怎样使用python画复杂函数_如何用python画常值函数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部