Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # Importing the math module, so we can use eulers e (e^x), written as exp(x) here.
- import math
- # Importing the pyplot module from matplotlib, so we can plot our findings
- import matplotlib.pyplot as plt
- # Defining Mega and Micro for easy use on component values
- Mega = 10**6
- Micro = 10**-6
- # Variables for our circuit.
- V = 5
- C = 1*Micro
- R = 100*Mega
- # This gives us a time constant of 100 seconds.
- # A time constant less than, or equal to 3s will result in a low resolution plot,
- # because we only sample one value each second.
- T_rc = R*C
- # We will use the following formula to calculate the voltage:
- # V(t) = V_0 (1-e^(-t/T)), which can be written as
- # V(t) = V*(1-e^(-t/R*C)), in our case. T = RC.
- # This is stored in V_t.
- V_t = []
- # A capacitor is 99.9% charged at 5 time constants.
- # We want to se it stabilize, so this for loop will find
- # values for V_t from 0 to 10 time constants. -> range(1, T_rc.__int__()*10)
- for t in range(1, T_rc.__int__()*10):
- # Formula for voltage over a capacitor at a given time, t.
- V_t.append(V*(1-math.exp(-t/(T_rc))))
- # Simple plotting of our findings.
- plt.plot(V_t)
- plt.grid()
- plt.xlabel("Time [s]")
- plt.ylabel("Current [A]")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment