Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Potential Difference Across 3 Resistors
- % Determines the voltage from point A to B when two resistors are in
- % parallel and the other is in series. Notes and clarifications are
- % at the bottom of the code.
- clc, clear
- resis = input('Input the resistances in brackets\n');
- a = input('Are you given the current across the resistors in series or parallel?\n');
- switch a
- case 1
- I(1) = input('What is the current across R1?\n');
- V(1) = I(1) * resis(1);
- V(2) = (I(1)*resis(2)*resis(3))/(resis(2)+ resis(3));
- Vsum = sum(V);
- case 2
- b = input('Are you given the current is across R2 or R3?\n');
- switch b
- case 1
- I(2) = input('What is the current across R2?\n');
- V(2) = I(2) * resis(2);
- I(3) = V(2)/resis(3);
- V(1) = (I(2) + I(3))*resis(1);
- Vsum = sum(V);
- case 2
- I(3) = input('What is the current across R3?\n');
- V(3) = I(3) * resis(3);
- I(2) = V(3)/resis(2);
- V(1) = (I(2) + I(3))*resis(1);
- Vsum = sum(V);
- end % switch b
- end
- fprintf('The potential difference across the resistors is %.3e V', Vsum);
- %{
- It is important for this code that the array 'V' be empty at the start
- because later on sum(V) is used and only the values calculated
- should be calculated.
- Potential difference is the same as the voltage.
- This code works under the assumption that R2 and R3 are in parallel with one
- another and that R1 would be in series.
- When prompted, the user needs to put the resistors in brackets [] for the
- code to work.
- The output is rounded to three places after the decimal point. This can be
- changed or removed by adjusting the .# in the fprintf line.
- %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement