因此,我需要计算左,中和右黎曼和,但是我进行计算的while循环已关闭。我不知道哪里出了问题,我正在与Symbolab进行核实,距离我只有一小会儿。
import numpy as np
import matplotlib.pyplot as plt
def plot(f, a = 0, b = 1, m = str('center'), n = 10):
par = (b - a)/1000
x = np.arange(a, b, par)
plt.plot(x, f(x), 'black')
w = (b - a)/n
i = 1
v = 0
if b < a:
raise ValueError('Value b must be greater than a', b)
if m not in ("center", "left","right"):
raise ValueError('Value m must be one of the following: center, left, or right', m)
if n < 0:
raise ValueError('N must be a positive integer', n)
if m == 'center':
d = w /2
x2 = np.arange(a + d , b + d , w)
plt.bar(x2,f(x2), align = 'center', color = 'blue',\
edgecolor = 'black', width = w, alpha = 0.5)
plt.show()
while( i<=(n)):
v += f(a+w*i) * w
i = i+1
print("The estimation using", m ,"is", v)
if m == 'left':
x2 = np.arange(a , b , w)
plt.bar(x2,f(x2), align = 'edge', color = 'red',\
edgecolor = 'black', width = w, alpha = 0.5)
plt.show()
while( i<=(n)):
v += f(a+w*i) * w
i = i+1
print("The estimation using", m ,"is", v)
if m == 'right':
x2 = np.arange(a + w, b + w , w)
plt.bar(x2,f(x2), align = 'edge', color = 'orange',\
edgecolor = 'black', width = -w, alpha = 0.5)
plt.show()
while( i<=(n)):
v += f(a+w*i) * w
i = i+1
print("The estimation using", m ,"is", v)
我不能始终如一地得到我用Symbolab检查的答案。