Python线性差分方程

时间:2016-05-10 13:55:08

标签: python differential-equations

所以我有3个方程式: R = 5,V = 10,C = 10

R C dUc(t)/ dt + Uc(t)= Vdc

i(t)= C * dUc(t)/ dt

Ur(t)= i(t)* R

我使用scypy dsolve解决了diff方程以获取Uc(t)但是我如何在其他方程中使用它?我试图将函数的导数用于第二个等式,但它告诉我不止一个变量。

我的代码:

from sympy import *
import numpy as nm
import pylab as pl
t = nm.arange(0,1,0.002)
r=5
v=10
c=10

#solving diff equation
t=Symbol('t')
u=Function('u')
uu= Derivative(u(t),t)
uc = dsolve(r*c*uu+u(t)-v,u(t))

#finding i
i = c * Derivative(uc)

#finding r
ur = i*r

#plot
t = nm.arange(0,1,0.002)
u = uc
i = c * Derivative(uc)
ur = i*r

pl.subplot(3,1,1)
pl.plot(t,u, '-r')
pl.grid()
pl.ylabel('capacitator voltage')

pl.subplot(3,1,2)
pl.plot(t,i, '-b')
pl.grid()
pl.ylabel('current')

pl.subplot(3,1,3)
pl.plot(t,r, '-')
pl.grid()
pl.ylabel('resistor')

pl.show

1 个答案:

答案 0 :(得分:0)

是衍生物需要两个必要的参数:函数和你想要衍生物的点。

所以我假设你想要

i = c * Derivative(uc, t)