Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.integrate import odeint
  4. import math
  5.  
  6. #function that puts the dirivative and second dirivative as list
  7. def RLC_ODE_INT(y, t, L = .05, R = 20, C = .0001, E = 100):
  8. charge, current = y
  9. E = 120*math.cos(120*3.141592*t)
  10. dydt = [current, (E - (current*R) - (charge/C))/L]
  11. return dydt
  12.  
  13. #define the constants
  14. L, R, C, E, t0, simLength, DT = .2, 50, .0001, 100, 0.0, .05, .0001
  15. # values in Henrys, ohms, Fardads, Volts, seconds, Seconds, and Seconds, respectivly
  16.  
  17. t = np.arange(t0, simLength+DT, DT) # Create the array for time t
  18.  
  19. # The initial condition for each dirivative which is needed in order for the constants of the general solution to be solved
  20. y0 = [10**(-6), 0.0] # The initial condition for the change and current
  21.  
  22. y = odeint(RLC_ODE_INT, y0, t, args=(L,R,C,E))
  23.  
  24. #plots the y(t) and y'(t) given from the odeint Function
  25. plt.plot(t, y[:, 0])
  26. plt.title('Charge vs Time', size = 12, weight='bold')
  27. plt.xlabel('Time (seconds)')
  28. plt.ylabel('Charge')
  29. plt.grid()
  30. plt.figure()
  31. plt.plot(t, y[:, 1])
  32. plt.title('Current vs Time', size = 12, weight='bold')
  33. plt.xlabel('Time (Seconds)')
  34. plt.ylabel('Current')
  35. plt.grid()
  36. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement