Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的黎曼计算有什么问题?_Python_Numpy_Sum - Fatal编程技术网

Python 我的黎曼计算有什么问题?

Python 我的黎曼计算有什么问题?,python,numpy,sum,Python,Numpy,Sum,所以我需要计算一个左,中,右的黎曼和,但我的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), '

所以我需要计算一个左,中,右的黎曼和,但我的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
这是突出的绘图,不需要分组 检查m是否有效
如果n<0:
raise VALUERROR('N必须是正整数',N)
检查n是否为正和整数
如果m=='center':
d=w/2
x2=np.arange(a+d,b+d,w)
plt.条(x2,f(x2),对齐='中心',颜色='蓝色'\
边缘颜色='黑色',宽度=w,alpha=0.5)
plt.show()

while(I)您的输入是什么?您的代码和符号AB得到了什么答案?有限ε的Rieman和会有一些错误这一事实与预期的差异是什么?您能否摆脱所有的绘图,并将所有内容组合成一个函数(或三个单独的函数)和一个返回值(每个)?您的输入是什么?您的代码和Symbolab得到了什么答案?有限epsilon的Rieman和会有一些错误这一事实与预期的差异是什么?您能否摆脱所有的绘图,并将所有内容组合成一个函数(或三个单独的函数)和一个返回值(每个)?
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)