How do I input this into the given MATLAB script? Equivalent resistance calculator (if-elseif-else, vector operations) The
Fantastic news! We've Found the answer you've been seeking!
Question:
How do I input this into the given MATLAB script?
Transcribed Image Text:
Equivalent resistance calculator (if-elseif-else, vector operations) The circuit diagram below shows resistors connected in series. owwwww R₂ R₁ R₁ (image source: The equivalent resistance for n resistors connected in series is given by: Requi= R₁ = R₁ + R₂ + R₂ + ... + R₂ https://commons.wikimedia.org/wiki/File:Resistors_in_series.svg ) The next circuit diagram below shows resistors connected in parallel. R1 Requi R2 (image source: https://commons.wikimedia.org/wiki/File:Resistors in parallel.svg) The equivalent resistance for n resistors connected in parallel is given by: + ++ R₁ R₁ R₂ Rn R₂ Code has already been provided to define a function named ResistorFun that accepts two input variables defined as follows: 1. The variable ResistorValues is a vector of any length greater than or equal to 2 that contains the resistance values of two or more resistors. 2. The variable Series_or_Parallel is a single character variable that is equal to the text S or number 1 to indicate a series connection or the text P or number 2 to indicate a parallel connection. Add code to the function to use the appropriate formula (as described above) to compute the equivalent resistance of a simple resistive circuit consisting of only series-connected or parallel-connected resistors. Your code should compute a single scalar value that is the equivalent resistance of the circuit and assign that value to the function output variable EquivResistance. If the second input is not one of the specified options for series or parallel, then the function output should change to the message Second input invalid. Use and if-elseif-else structure in your solution. Note the variables ResistorValues and Series_or_Parallel are defined as inputs to the function. Do not overwrite these values in your code. Be sure to assign a value to the output variable EquivResistance. Function > 1 function EquivResistance = ResistorFun( ResistorValues, Series_or_Parallel ) 2 Enter the code for your function here. 3 if Series_or_Parallel == S || 4 5 elseif Series_or_Parallel == 6 EquivResistance = sum( EquivResistance = Second 7 else 8 9 end EquivResistance = sum(ResistorValues0; 10 11 end Save Code to call your function > C Reset 1 EquivResistance1 = ResistorFun ( [333 1000 500], S ) %test series case. 2 EquivResistance2 = ResistorFun ( [333 1000 500], 2) stest parallel case 3 EquivResistance3= ResistorFun ( [333 1000 5001, 3) %test invalid input case MATLAB Documentation C Reset Equivalent resistance calculator (if-elseif-else, vector operations) The circuit diagram below shows resistors connected in series. owwwww R₂ R₁ R₁ (image source: The equivalent resistance for n resistors connected in series is given by: Requi= R₁ = R₁ + R₂ + R₂ + ... + R₂ https://commons.wikimedia.org/wiki/File:Resistors_in_series.svg ) The next circuit diagram below shows resistors connected in parallel. R1 Requi R2 (image source: https://commons.wikimedia.org/wiki/File:Resistors in parallel.svg) The equivalent resistance for n resistors connected in parallel is given by: + ++ R₁ R₁ R₂ Rn R₂ Code has already been provided to define a function named ResistorFun that accepts two input variables defined as follows: 1. The variable ResistorValues is a vector of any length greater than or equal to 2 that contains the resistance values of two or more resistors. 2. The variable Series_or_Parallel is a single character variable that is equal to the text S or number 1 to indicate a series connection or the text P or number 2 to indicate a parallel connection. Add code to the function to use the appropriate formula (as described above) to compute the equivalent resistance of a simple resistive circuit consisting of only series-connected or parallel-connected resistors. Your code should compute a single scalar value that is the equivalent resistance of the circuit and assign that value to the function output variable EquivResistance. If the second input is not one of the specified options for series or parallel, then the function output should change to the message Second input invalid. Use and if-elseif-else structure in your solution. Note the variables ResistorValues and Series_or_Parallel are defined as inputs to the function. Do not overwrite these values in your code. Be sure to assign a value to the output variable EquivResistance. Function > 1 function EquivResistance = ResistorFun( ResistorValues, Series_or_Parallel ) 2 Enter the code for your function here. 3 if Series_or_Parallel == S || 4 5 elseif Series_or_Parallel == 6 EquivResistance = sum( EquivResistance = Second 7 else 8 9 end EquivResistance = sum(ResistorValues0; 10 11 end Save Code to call your function > C Reset 1 EquivResistance1 = ResistorFun ( [333 1000 500], S ) %test series case. 2 EquivResistance2 = ResistorFun ( [333 1000 500], 2) stest parallel case 3 EquivResistance3= ResistorFun ( [333 1000 5001, 3) %test invalid input case MATLAB Documentation C Reset
Expert Answer:
Answer rating: 100% (QA)
How do I input this into the given MATLAB script Answer 1 The code to call the function can be input... View the full answer
Related Book For
College Physics
ISBN: 978-0495113690
7th Edition
Authors: Raymond A. Serway, Jerry S. Faughn, Chris Vuille, Charles A. Bennett
Posted Date:
Students also viewed these programming questions
-
Given a square matrix [A], write a single line MATLAB command that will create a new matrix [Aug] that consists of the original matrix [A] augmented by an identity matrix [I]?
-
How can political factors be an input into accounting policy-making if the latter is concerned with governing and making the rules for financial accounting?
-
I don't see any reason to do this net present value stuff. The payback method works well for me. It tells me how many years it takes to recoup the initial money I put in. As long as my payback period...
-
Casrnir proposes a model of third-culture building to account for the evolutionary nature of intercultural dialogue. What role do you think the many studies on cultural dimensions can play in the...
-
Does the auditor need to engage another independent specialist to test the work of the specialist hired by the company to determine the value of the tangible and intangible assets other than...
-
US Export Laws never apply to products that are manufactured overseas True False
-
In Exercises 9 and 10, use the given set of points to a. Compute b0 and b1. b. Compute the predicted value y for the given value of x. c. Compute the residual standard deviation se. d. Compute the...
-
Plants Plus operates a commercial plant nursery, where it propagates plants for garden centers throughout the region. Plants Plus has $4,950,000 in assets. Its yearly fixed costs are $650,000, and...
-
B. Cost of Sales Part 2: (5 x 2 points = 10 points) Write your answer before each no. Administrative Selling Net Cost of CASES Income Sales 48,000.0 1 0 Expenses 15% of Sales Expenses 13% of Sales OR...
-
Carrie DLake, Reed A. Green, and Doug A. Divot share a passion for golf and decide to go into the golf club manufacturing business together. On January 2, 2020, DLake, Green, and Divot form the...
-
At a time when he owns total assets with a market value of $30,000 and has liabilities of $65,000, Peter Price files for bankruptcy and all debts are discharged. How much gross income, if any, must...
-
What is the difference between an empirical study, and other academic work?
-
Does the salinity measured by the refractometers confirm or counter the measurements made by the hydrometers?
-
What is an example of Requisite Variety that is brought about by Globalization issues and how organizations might address such issues.
-
In the context of cellular respiration, what molecular mechanisms regulate the synthesis and utilization of ATP, the primary energy currency of cells, and how do respiratory substrates like glucose...
-
Factor each polynomial Completely. 2 14z-15z+4 2 2 x - 17x+12 2 4w-14 w (4) 4+2 +12++9
-
What is the output of the following code snippet? int number = 4; if (number++ > --number) number += 4; if (number % 2 == 0 && number % 2 == 1) number += 5; else if (++number < 4). number -= 3;...
-
If M = 7, s = 2, and X = 9.5, what is z?
-
A ball is dropped from rest 3.00 m directly above the vertex of a concave mirror having a radius of 1.00 m and lying in a horizontal plane. (a) Describe the motion of the balls image in the mirror....
-
Consider the circuit shown in figure. Take ? = 6.00 V, L = 8.00 mH, and R = 4.00 ?. (a) What is the inductive time constant of the circuit? (b) Calculate the current in the circuit 250 ?s after the...
-
A solenoid 4.00 cm in diameter and 20.0 cm long has 250 turns and carries a current of 15.0 A. Calculate the magnetic flux through the circular cross-sectional area of the solenoid.
-
What are the different ways digital technology advancements disrupt the audit function?
-
How can digital technology transform financial reporting from static information provision to active engagement?
-
Identify four changed accounting roles and activities as a result of digital technology advancements.
Study smarter with the SolutionInn App