Advertisement
hiddenGem

Potential Difference Among 3 Resistors

Jun 18th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.64 KB | None | 0 0
  1. %% Potential Difference Across 3 Resistors
  2. % Determines the voltage from point A to B when two resistors are in
  3. % parallel and the other is in series. Notes and clarifications are
  4. % at the bottom of the code.
  5.  
  6. clc, clear
  7.  
  8. resis = input('Input the resistances in brackets\n');
  9. a = input('Are you given the current across the resistors in series or parallel?\n');
  10.  
  11. switch a
  12.     case 1
  13.         I(1) = input('What is the current across R1?\n');
  14.         V(1) = I(1) * resis(1);
  15.         V(2) = (I(1)*resis(2)*resis(3))/(resis(2)+ resis(3));
  16.         Vsum = sum(V);
  17.     case 2
  18.         b = input('Are you given the current is across R2 or R3?\n');
  19.         switch b
  20.             case 1
  21.                 I(2) = input('What is the current across R2?\n');
  22.                 V(2) = I(2) * resis(2);
  23.                 I(3) = V(2)/resis(3);
  24.                 V(1) = (I(2) + I(3))*resis(1);
  25.                 Vsum = sum(V);
  26.             case 2
  27.                 I(3) = input('What is the current across R3?\n');
  28.                 V(3) = I(3) * resis(3);
  29.                 I(2) = V(3)/resis(2);
  30.                 V(1) = (I(2) + I(3))*resis(1);
  31.                 Vsum = sum(V);
  32.         end % switch b
  33. end
  34. fprintf('The potential difference across the resistors is %.3e V', Vsum);
  35.  
  36. %{
  37. It is important for this code that the array 'V' be empty at the start
  38.     because later on sum(V) is used and only the values calculated
  39.     should be calculated.
  40. Potential difference is the same as the voltage.
  41. This code works under the assumption that R2 and R3 are in parallel with one
  42.     another and that R1 would be in series.
  43. When prompted, the user needs to put the resistors in brackets [] for the
  44.     code to work.
  45. The output is rounded to three places after the decimal point. This can be
  46.     changed or removed by adjusting the .# in the fprintf line.
  47. %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement