hiddenGem

Discharging a Capacitor Through a Resistor

Jun 21st, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.67 KB | None | 0 0
  1. %% Discharging a Capacitor Through a Resistor
  2. % Calculates the voltage across a capacitors after a certain amount of time
  3. %   passes. Notes and clarifications are at the end of the code
  4.  
  5. % Inputs and Variables
  6. C = input('What is the capacitance in Faradays?\n');
  7. V0 = input('What is the initial potential difference across the circuit in volts?\n');
  8. R = input('What is the resistance in ohms?\n');
  9. t = input('How many seconds later?\n');
  10.  
  11. % Outputs and Equations
  12. V = V0*exp(-t/(R*C))
  13. fprintf('The new potential difference is %.4e V', V);
  14.  
  15. %{
  16. The output is rounded to after the 4th decimal place. You can change this by
  17.     adjusting or removing the .# in the fprintf line.
  18. %}
Add Comment
Please, Sign In to add comment