无法分配给函数调用(Python)

2024-09-20 22:54:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

class Quadratic:

    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

    def function(self, x):
        self.F(x) = a*(x**2) + b*x + c
        return F(x)

    def table(self, lower, upper, varz):
        inc = np.absolute(upper-lower) / varz
        print inc
        for i in range(0 , varz - 1):
            self.F(lower)
            lower = lower + inc
        #lower bound,upper bound, number of values

    def roots():
        x1 = (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)
        x2 = (-b - math.sqrt(b**2 - 4*a*c)) / (2*a)
        return x1, x2

    def dump(self):
        print self.n

每当我尝试运行此脚本时,都会得到以下结果:

^{pr2}$

任何帮助或想法都将不胜感激。在


Tags: 代码selfreturndefmathsqrtupperlower
3条回答

目前还不清楚(至少对我来说)你想要达到的目标是什么,但也许就这么简单:

def F(self, x):
    return self.a * (x ** 2) + self.b * x + c

尝试使用:

def __init__(self, a,b,c):
    self.a = a
    self.b = b
    self.c = c
    self.F = lambda x: a*(x**2)+b*x+c

并放弃function()方法

您可能已经猜到,F(x)是一个函数调用。您调用的函数F,它实际上并不存在,并向它传递参数x,它实际上也不存在。您需要给变量提供合法的名称,比如f_of_x。在

相关问题 更多 >

    热门问题