将所有x值绘制到给定数学函数的方法

时间:2016-09-29 15:18:07

标签: python

嘿,我需要帮助编写一个方法,将所有x值绘制成给定的数学函数

def compute(expression):  #The expression is where the math function is gonna be placed
    print("Evaluerer", expression)

    for i in range(0,1001):
        x=i/100.0 #This is all the x-values, which needs to be put into the expression

感谢您的回复

1 个答案:

答案 0 :(得分:0)

定义你的功能:

def f(x):
    return x #put here your expression of f(x)

然后将您的功能绘制如下:

plt.plot([i/100.0 for i in range(0,1001)], map(lambda x: f(x),[i/100.0 for i in range(0,1001)]))