To study the growth and decay of current in RL circuit containing (a) DC source and (b) AC using Runge-Kutta method, and to draw graphs between current and time in each case.

 To study the growth and decay of current in RL circuit containing (a) DC source and (b) AC using Runge-Kutta method, and to draw graphs between current and time in each case.







Python Code:

# ---------------------------------------------------------------
# exp -10: To study the growth and decay of current in RL circuit
# containing DC source using Runge - Kutta method , and to draw
# graphs between current and time in each case
# ---------------------------------------------------------------
import numpy as np
import math
import matplotlib . pyplot as plt

e = 1.0# emf ( volt )
r = 0.2# resistance ( Ohm )
l = 1.0# inductor ( Henry )

tf = 30.0 # final time of t
dt = 0.1 # step size

n = int ( tf / dt )
# -------- Growth of current ------------------------------------
def f(t ,i ): # growth of current
  return (e - i*r /l)
# ---------------------------------------------------------------
ii = [ None ]* n
tt = [ None ]* n
t = 0.0; i = 0.0;
ii [0] = i; tt [0] = t; # initial value for rk4

for j in range (0 , n , 1) :
  k1 = dt * f(t ,i );
  k2 = dt * f(t+ dt /2.0 , i + k1 /2.0) ;
  k3 = dt * f(t+ dt /2.0 , i + k2 /2.0) ;
  k4 = dt * f(t+dt , i+ k3 ) ;
  i = i + (1.0/6.0) *( k1 + 2.0* k2 + 2.0* k3 + k4 )
  t += dt

  ii [j] = i
  tt [j] = t

# ----------- decay of current function - ----- ---- ----- ----- ---- --
def g(t ,i ):
  return (-i* r/l)
# ---------------------------------------------------------------
iid = [ None ]* n
ttd = [ None ]* n
t = 0.0; i = ii [n -1];
iid [0] = i; ttd [0] = t ; # initial value for rk2

for j in range (0 , n , 1) :
  k1 = dt * g(t ,i );
  k2   = dt * g(t+ dt /2.0 , i + k1 /2.0) ;
  k3 = dt * g(t+ dt /2.0 , i + k2 /2.0) ;
  k4 = dt * g(t+dt , i+ k3 ) ;
  i = i + (1.0/6.0) *( k1 + 2.0* k2 + 2.0* k3 + k4 )
  t += dt

  iid [j ] = i
  ttd [j ] = t
#------------ plotting I vs time ( Growth ) -------------------------
f = plt . figure ( figsize =(10 ,3) )

plt . subplot (1 , 21)
plt . plot (tt ,ii ,'-r', linewidth =4.0) ; plt . grid () ;
plt . xlim (0 , 30) ;
plt . ylim (0 , 5) ;
plt . xlabel (" Time ( sec )", fontsize =14) ;
plt . ylabel (" Current I ( amp )", fontsize =14) ;
plt . title (" Growth of Current ", fontsize =14)
# ------------ plotting I vs time ( Decay ) ------------------------
plt . subplot (1 , 22)
plt . plot ( ttd , iid ,'-r', linewidth =4.0) ; plt . grid () ;
plt . xlim (0 , 30) ;
plt . ylim (0 , 5) ;
plt . xlabel (" Time ( sec )", fontsize =14) ;
plt . ylabel (" Current I ( amp )", fontsize =14) ;
plt . title (" Decay of Current ", fontsize =14) ;

plt . savefig ("exp10.png", bbox_inches ="tight", dpi =600)
plt . show ()
# ----------------------------------------------------------------















Comments

Popular posts from this blog

Solving Van Der Waals gas equation for volume of a real gas by the method of successive approximation.

To interpolate a real data set from an experiment using the Lagrange’s method, and Newton’s method of forward differences.

To find the area of a unit circle by Monte Carlo integration.