Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Two Resistors in Parallel
- % Calculates the voltage and individual currents across the resistors
- % Notes and clarifications are at the bottom of the code.
- resis = input('Input resistances in brackets\n');
- a = input('Given the current of R1 or R2?\n');
- switch a
- case 1
- I(1) = input('Current across R1\n');
- V = I(1)*resis(1);
- I(2) = V/resis(2);
- case 2
- I(2) = input('Current across R2\n');
- V = I(2)*resis(2);
- I(1) = V/resis(1);
- end
- Isum = sum(I);
- fprintf(['The voltage and individual and total currents are \n', ...
- '%.4e V, %.3i A, %.3i A, %.3i A'], V, I, Isum)
- %{
- When prompted, the user needs to input the resistors in brackets []
- The output values are rounded to the third decimal place. To change or remove
- this edit the .# in the last line of the fprintf.
- The output gives values in the order of voltage across the resistors, the
- individual currents across the resistors, and the sum of the current
- across both resistors.
- %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement