Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Two Resistors in Series
- % Calculates the electric current and total potential difference across the
- % two resistors. Notes and clarifications at the end of code.
- % Inputs and Variables
- resis = input('Input resistances in brackets\n');
- a = input('Given the Voltage of R1 or R2?\n');
- switch a
- case 1
- V(1) = input('Voltage across R1\n');
- I = V(1)/resis(1);
- V(2) = I * resis(2);
- case 2
- V(2) = input('Voltage across R2\n');
- I = V(2)/resis(2);
- V(1) = I * resis(1);
- end
- Vsum = sum(V);
- fprintf(['The current and individual and total voltages are \n', ...
- '%.3e A, %.3i V, %.3i V, %.3i V'], I, V, Vsum)
- %{
- The user must enter the resistances in brackets [] for the code to work
- The outputs are rounds to three decimal places. This can be adjust through
- changing for removing the .# in the last fprintf line.
- The output lists current through both, voltage through the first
- resistor, voltage through the second resistor, and the total
- voltage through the series.
- %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement