0% found this document useful (0 votes)
74 views4 pages

Runge Krupta Kirchoff Law Python

The document presents a circuit analysis problem involving Kirchhoff's laws and a series RLC circuit. It sets up the system of first-order differential equations describing the circuit and uses the 4th order Runge-Kutta method to numerically solve for the currents and capacitor charge over time. The solutions are plotted, showing how the currents and charge vary as the circuit reaches steady state.

Uploaded by

]Arhur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views4 pages

Runge Krupta Kirchoff Law Python

The document presents a circuit analysis problem involving Kirchhoff's laws and a series RLC circuit. It sets up the system of first-order differential equations describing the circuit and uses the 4th order Runge-Kutta method to numerically solve for the currents and capacitor charge over time. The solutions are plotted, showing how the currents and charge vary as the circuit reaches steady state.

Uploaded by

]Arhur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Equipo 8 Problema de sistemas de ecuaciones de leyes de kirchoff tomado del link

http://people.uncw.edu/hermanr/mat361/ODEBook/Systems.pdf usando runge krupta de 4 orden.

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)

K1 = h*F(x + h/2.0, y + K0/2.0)

K2 = h*F(x + h/2.0, y + K1/2.0)

K3 = h*F(x + h, y + K2)

return (K0 + 2.0*K1 + 2.0*K2 + K3)/6.0

X = []

Y = []

X.append(x)

Y.append(y)

while x < xStop:

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("\n x ",end=" ")

for i in range (n):

print(" y[",i,"] ",end=" ")

print()

def printLine(x,y,n):

print("{:13.4e}".format(x),end=" ")

for i in range (n):

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)

if i != m - 1: printLine(X[m - 1],Y[m - 1],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):

# the vector y is = [ q_1(t), q_2(t), i_1(t), i_2(t) ]

q_1, q_2, i_1, i_2 = y

F = zeros( (4,), dtype=float )

F[0] = i_1

F[1] = i_2

F[2] = E/L - (R/L) * i_1 - ( q_1 - q_2 )/LC

F[3] = -q_2/LC - ( q_2 - q_1 )/LC - (R/L) * i_2

return F

t0 = 0.0 # start of the integration

tStop = 0.01 # end of the integration

h = 1.e-2

freq = 0

y0 = asarray( [ 0., 0., 0., 0. ], dtype=float )

T,Y = integrate(F,t0,y0,tStop,h)

printSoln(T,Y,freq)

if True:

pylab.plot( T, Y[:,2], label='i_1(t)' )


pylab.plot( T, Y[:,3], label='i_2(t)' )

pylab.xlabel('t (time)')

pylab.legend(loc='best')

pylab.grid('on')

You might also like