Advertisement
hiddenGem

Electric Circuit of 5 Resistors

Jun 18th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.52 KB | None | 0 0
  1. %% Electric Circuit of 5 Resistors
  2. % Determines the equivalent resistance of the circuit
  3. % Notes and Clarifications are at the end of the code
  4.  
  5. % Inputs and Variables
  6. resis = input('Input resistances in brackets\n');
  7.  
  8. % Outputs and Equations
  9. Rtot = resis(1) + resis(4) + (resis(3)*(resis(2)+resis(5)))/(resis(3)+(resis(2)+resis(5)));
  10. fprintf('The total resistance is %.3e \n', Rtot);
  11.  
  12. if range(resis) == 0
  13.     a = input('Would you like the calculate the current through R2 or R5? Y/N \n ', 's');
  14.     if a == 'Y'
  15.         V = input('What is the voltage of the circuit?\n');
  16.         I = (V/Rtot)/resis(1);
  17.         fprintf('The current running through R2/R5 is %.3e A \n', I)
  18.     end
  19. end
  20. %{
  21. The 'if' statement input requires a Y as a response to proceed with
  22.     calculating the optional step.
  23. Under the assumption that the resistors are in an 'x' formation while the
  24.     numbering of the resistors is in a 'z' formation with R1 at the top left
  25.     and R5 is at the bottom right.
  26.  
  27. If all the resistors have equal resistance, the amount of current that goes
  28.     into R2 or R5 can be calculated. It can be calculated by finding the net
  29.     current and dividing it by the resistance of an individual resistor.
  30.     The code will run this optional path if requirements are met.
  31.  
  32. To solve this manually
  33.     R2 and R5 are in series so they are added together  to equal R25
  34.     R3 and R25 are is parallel so the inverse of the inverses added
  35.         together equal R3,25
  36.     R1, R4, and R3,25 are in series so they are added together
  37. %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement