python中积分的导数

时间:2013-12-31 08:20:16

标签: python

我有一个带有两个变量f(x,y)= x + 2y的函数,我想将它相对于x进行积分然后相对于y取导数,然后用y绘制结果,这是我的代码:

import numpy as np
import matplotlib.pyplot as plt
import math
import scipy.integrate
from scipy.misc import derivative



x = raw_input("enter x: "); x=float(x)
y = raw_input("enter y: "); y=float(y)

def f1(x,y):

  r=x+2*y
  return r
r=f1(x,y)
print "r=",r

def int(y):
    return scipy.integrate.quad(f1, 0,x,args=(y))
vint=np.vectorize(int)
ylist=np.linspace(0,y,10)
results,errs=vint(ylist)
plt.plot(ylist,results)
plt.show()


def dI(y):
   return derivative(int,y)


vdI=np.vectorize(dI)
sol,err=vdI(ylist)
plt.plot(ylist,sol)
plt.show()

但我收到此错误消息:

 val += weights[k]*func(x0+(k-ho)*dx,*args)
 TypeError: unsupported operand type(s) for +=: 'float' and 'tuple'

我做错了什么?提前谢谢。

0 个答案:

没有答案