Fixed_quad错误函数

时间:2014-11-24 17:48:40

标签: python python-2.7

保持简单:

----------------------------------

from mpmath import *
from scipy.integrate import *
mp.dps=30
def F(x):
    return Q**(x)
Q=735
print fixed_quad(F,0,1,n=1)[0]
print fixed_quad(F,0,1,n=2)[0]
print fixed_quad(F,0,1,n=3)[0]
--------------------
returns
 27.1108834235
 93.1213589089
109.673420158

但是,如果我将F(x)从“Q **(x)”更改为一个简单的函数 - 例如“cos(x)” - 我得到

--------------------
Traceback (most recent call last):
  File "Test.py", line 7, in <module>
    print fixed_quad(F,0,1,n=1)[0]
  File "/usr/lib/python2.7/dist-packages/scipy/integrate/quadrature.py", line 67, in fixed_quad
    return (b-a)/2.0*sum(w*func(y,*args),0), None
  File "Test.py", line 5, in F
    return cos(x)
  File "/usr/lib/pymodules/python2.7/mpmath/ctx_mp_python.py", line 984, in f
    x = ctx.convert(x)
  File "/usr/lib/pymodules/python2.7/mpmath/ctx_mp_python.py", line 662, in convert
    return ctx._convert_fallback(x, strings)
  File "/usr/lib/pymodules/python2.7/mpmath/ctx_mp.py", line 614, in _convert_fallback
    raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from array([ 0.5])

这是一些已知的错误吗?或者“fixed_quad”仅用于某些用途,而不是一般集成(如“trapz”)?

所有其他常客(“quad”,“dblquad”,“tplquad”,“nquad”)似乎都没有出现这个问题/错误。

0 个答案:

没有答案