【发布时间】:2018-05-24 04:45:02
【问题描述】:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.integrate import quad
lo = input("What is your lower bound")
up = input("What is your upper bound")
def f(x):
return equation
i= int(quad(f(x), lo, up))
while True:
if i < 0:
print ("invalid")
elif i.isalpha:
print("invalid")
elif i == "":
print("invalid")
else:
print("invalid")
print(i[0])
我遇到了这个错误
TypeError Traceback (most recent call last)
<ipython-input-76-9a1a8ce0b385> in <module>()
11 return equation
12
---> 13 i= int(quad(f(x), lo, up))
14
15 while True:
~/anaconda3/lib/python3.6/site-packages/scipy/integrate/quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
321 if (weight is None):
322 retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
--> 323 points)
324 else:
325 retval = _quad_weight(func, a, b, args, full_output, epsabs, epsrel,
~/anaconda3/lib/python3.6/site-packages/scipy/integrate/quadpack.py in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
386 if points is None:
387 if infbounds == 0:
--> 388 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
389 else:
390 return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
**TypeError: must be real number, not str**
【问题讨论】:
-
什么是
equation? -
下次阅读错误消息 -
**TypeError: must be real number, not str**- 并检查变量中的值以找出哪个保留字符串 - 即。print(variable, type(variable))
标签: python numpy matplotlib integration integral