【发布时间】:2018-10-15 07:46:50
【问题描述】:
我想将没有封闭形式解决方案的函数与未知变量集成,然后绘制与未知变量的关系图。为了尝试更简单的测试,我尝试使用f(x,c) = (x^2+c) 的积分,相对于x 积分并使用c 的不同值进行绘图。但是,下面的代码得到了错误
只有 size-1 的数组可以转换为 Python 标量
即使一个数字的积分,例如integral(5),似乎返回了正确的标量值。
import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate
def f(x,c):
return x**2+c
def integral(c):
return integrate.quad(f,0,10, args = (c,))[0]
y = np.linspace(0,20,200)
plt.plot(y, integral(y))
【问题讨论】:
-
你真的不应该写一个叫做
int的函数。它与the built-in function 造成不必要的混淆。 -
你的变量
test是什么? -
我猜
test应该是f,因为它是上面定义的函数 -
已编辑将 int 函数更改为整数并修复了测试错字
标签: python plot scipy integral