[英]Why is a float type object not callable here?
I'm trying to make a Taylor series in Python and I don't know how to remove this error:我正在尝试在 Python 中制作泰勒级数,但我不知道如何删除此错误:
x=Symbol("x")
def f(x):
return ((math.e)**x)*sin(x)
y=f(x)
print(y.diff(x))
def Taylor(f,x,m,a):
y=f(x)
y2=f
yargliige=0
viga = 10**(-m)
n=0
while True:
if n>10:
return yargliige,n
else:
yargliige+=(y(x)*(x-a)**n)/(factorial(n))
y=y.diff(x)
if abs(yargliige(x)-f(x))<viga:
return yargliige,n
n+=1
print(Taylor(f,-0.3,3,-1))
Error message I get:我得到的错误信息:
Traceback (most recent call last):
File "C:\Users\arman\Desktop\Numbrilised meetodid\praktikum10.py", line 31, in <module>
print(Taylor(f,-0.3,3,-1))
File "C:\Users\arman\Desktop\Numbrilised meetodid\praktikum10.py", line 25, in Taylor
yargliige+=(y(x)*(x-a)**n)/(factorial(n))
TypeError: 'Float' object is not callable
It seems that the original function doesn't accept float, which seems ridiculous.好像原来的function不接受float,看起来很可笑。
You've already called y = f(x)
which stores the returned float
from the function f
.您已经调用了
y = f(x)
来存储从 function f
返回的float
。 You can not do y()
as y
is not callable.你不能做
y()
因为y
是不可调用的。 Change y = f(x)
to y = f
and it should solve your use case.将
y = f(x)
更改为y = f
,它应该可以解决您的用例。
I see that you are trying to call yargliige
as a function yargliige(x)
which is not applicable since it's a variable not function.我看到您试图将
yargliige
称为 function yargliige(x)
,这是不适用的,因为它是一个变量而不是 function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.