Untitled
unknown
plain_text
4 years ago
983 B
6
Indexable
import matplotlib.pyplot as plt
from math import *
R1=0.53*pow(10,-4)
R2=0.55*pow(10,-4)
C1=2.5*pow(10,-2)
C2=2*pow(10,-2)
qi1=0.5*pow(10,-4)
qi2=1*pow(10,-4)
tf=10
h=0.001
A,B,C=[],[],[]
def d(x1,x2,t):
return (-1/(R1*C1)*x1+(1/(R1*C1))*x2+(qi1/C1))
def f(x1,x2,t):
return (1/(R1*C2)*x1)-(1/(R1*C2)+(1/(R2*C2)))*x2+(qi2/C2)
def rungekutta(d,f,x1_0,x2_0,t0):
while t0<tf:
t=t0+h
k1=d(x1_0,x2_0,t0)
k2=d(x1_0+(h/2)*k1,x2_0+(h/2)*k1,t0+h/2)
k3=d(x1_0+(h/2)*k2,x2_0+(h/2)*k2,t0+h/2)
k4=d(x1_0+h*k3,x2_0+h*k3,t0+h)
l1=d(x1_0,x2_0,t0)
l2=d(x1_0+(h/2)*l1,x2_0+(h/2)*l1,t0+h/2)
l3=d(x1_0+(h/2)*l2,x2_0+(h/2)*l2,t0+h/2)
l4=d(x1_0+h*l3,x2_0+h*l3,t0+h)
x1=x1_0*(h/6)*(k1+2*k2+2*k3+k4)
x2=x2_0*(h/6)*(l1+2*l2+2*l3+l4)
x1_0=x1
x2_0=x2
t0=t
A.append(t)
B.append(x1)
C.append(x2)
return x1,x2,t
a=rungekutta(d,f,0,0,0)
print(a)Editor is loading...