Introduction
The purpose of this lab is to practice defining and using your own functions in MATLAB. For this exercise, we will be writing a circuit solver for three resistors in series:
Figure 1. Series Resistive Circuit
and three resistors in parallel:
Figure 2. Parallel Resistive Circuit
Procedure
As usual, include a comment at the top explaining the purpose of the script, your name, and the date it was created.
- Create a main script called main.m. In this script, you will be:
- Creating three variables for three resistance values and a variable for the voltage source value. Be sure your variable names reflect what the variable is storing.
- Calling functions and storing output for computing the series and parallel equivalent resistances, and power.
- Communicating with the user.
- Create a function that computes the equivalent resistance for resistors in series. The function should take in as input the three resistance variables you defined in your main function and it should return as output the equivalent resistance. For series resistors, equivalent resistance is:
3. Create a second function that computes the equivalent resistance for resistors in parallel. The function should take in as input the three resistance variables you defined in your main function and it should return as output the equivalent resistance. For parallel resistors, equivalent resistance is:
4. Create a third function that computes current and power delivered by the voltage source. Your function should take in as input the equivalent resistance and return two outputs, current and power. Let equivalent resistance be denoted Req, then, current and power are:
5. Run two cases of your code and report to the user the results of your calculations. The test cases are:
Test Case 1: R1 = 120 Ohms, R2 = 230 Ohms and R3 = 250 Ohms. Voltage source = 10V.
Test Case 2: R1 = 25 Ohms, R2 = 70 Ohms and R3 = 100 Ohms. Voltage source = 9V.
Your communication should follow the format:
“For resistances 100 Ohm, 200 Ohm and 300 Ohms, the equivalent resistance in series is 600 Ohms.”
“For a 12V voltage source, the source current supplied is .02 Amps and the power supplied is .24 Watts.”
“For resistances 100 Ohm, 200 Ohm and 300 Ohms, the equivalent resistance in parallel is 54.545454 Ohms.”
“For a 12V voltage source, the source current supplied is .22 Amps and the power supplied is 2.64 Watts.”