Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy.integrate import odeint
- #function that puts the dirivative and second dirivative as list
- def RLC_ODE_INT(y, t, L = .05, R = 20, C = .0001, E = 100):
- charge, current = y
- dydt = [current, (E - (current*R) - (charge/C))/L]
- return dydt
- #define the constants
- L, R, C, E, t0, simLength, DT = .05, 20, .0001, 100, 0.0, .05, .0001
- # values in Henrys, ohms, Fardads, Volts, seconds, Seconds, and Seconds, respectivly
- t=np.arange(t0, simLength+DT, DT) # Create the array for time t
- # The initial condition for each dirivative which is needed in order for the constants of the general solution to be solved
- y0 = [0.0, 0.0] # The initial condition for the change and current
- y=odeint(RLC_ODE_INT, y0, t, args=(L,R,C,E))
- #plots the y(t) and y'(t) given from the odeint Function
- plt.plot(t, y[:, 0])
- plt.title('Charge vs Time', size = 12, weight='bold')
- plt.xlabel('Time (seconds)')
- plt.ylabel('Change')
- plt.grid()
- plt.figure()
- plt.plot(t, y[:, 1])
- plt.title('Current vs Time', size = 12, weight='bold')
- plt.xlabel('Time (Seconds)')
- plt.ylabel('Current')
- plt.grid()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement