Runge Krupta Kirchoff Law Python
Runge Krupta Kirchoff Law Python
12. Consider the series circuit in Figure 6.21 with L = 1.00 H, R1 = R2 = 1.00 × 102
Ω, C = 1.00 × 10−4 F, and V0 = 1.00 × 103 V. a. Set up the problem as a system of
first order differential equations for the charges and the currents in each loop. b.
Suppose that no charge is present and no current is flowing at time t = 0 when
V0 is applied. Find the current and the charge on the capacitor as functions of
time. c. Plot your solutions and describe how the system behaves over time.
Código
## module runkut4
import numpy as np
def integrate(F,x,y,xStop,h):
def runkut4(F,x,y,h):
K0 = h*F(x,y)
K3 = h*F(x + h, y + K2)
X = []
Y = []
X.append(x)
Y.append(y)
h = min(h,xStop - x)
y = y + runkut4(F,x,y,h)
x=x+h
X.append(x)
Y.append(y)
return np.array(X),np.array(Y)
## module printSoln
def printSoln(X,Y,freq):
def printHead(n):
print()
def printLine(x,y,n):
print("{:13.4e}".format(x),end=" ")
print("{:13.4e}".format(y[i]),end=" ")
print()
m = len(Y)
try: n = len(Y[0])
except TypeError: n = 1
if freq == 0: freq = m
printHead(n)
for i in range(0,m,freq):
printLine(X[i],Y[i],n)
import numpy as np; from numpy import asarray, zeros, sin, cos, pi
if True:
integrate
else:
break
import pylab
E = 1.*1e3
R = 1.*1e2
L = 1.
C = 1. * 1e-4
LC = L*C
def F(t,y):
F[0] = i_1
F[1] = i_2
return F
h = 1.e-2
freq = 0
T,Y = integrate(F,t0,y0,tStop,h)
printSoln(T,Y,freq)
if True:
pylab.xlabel('t (time)')
pylab.legend(loc='best')
pylab.grid('on')