Advertisement
Guest User

Untitled

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