Advertisement
hiddenGem

Two Resistors in Parallel

Jun 17th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.83 KB | None | 0 0
  1. %% Two Resistors in Parallel
  2. % Calculates the voltage and individual currents across the resistors
  3. % Notes and clarifications are at the bottom of the code.
  4.  
  5. resis = input('Input resistances in brackets\n');
  6. a = input('Given the current of R1 or R2?\n');
  7. switch a
  8.     case 1
  9.         I(1) = input('Current across R1\n');
  10.         V = I(1)*resis(1);
  11.         I(2) = V/resis(2);
  12.     case 2
  13.         I(2) = input('Current across R2\n');
  14.         V = I(2)*resis(2);
  15.         I(1) = V/resis(1);
  16. end
  17. Isum = sum(I);
  18. fprintf(['The voltage and individual and total currents are \n', ...
  19.        '%.4e V,  %.3i A, %.3i A, %.3i A'], V, I, Isum)
  20.  
  21. %{
  22. When prompted, the user needs to input the resistors in brackets []
  23. The output values are rounded to the third decimal place. To change or remove
  24.     this edit the .# in the last line of the fprintf.
  25. The output gives values in the order of voltage across the resistors, the
  26.     individual currents across the resistors, and the sum of the current
  27.     across both resistors.
  28. %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement