Question

7. Write a function M-file that will compute the equivalent resistance for a series or parallel combination of an arbitrary number of resistors. Your function should: accept as input an arbitrary number of resistor values, stored in a vector ask the user to input p if the resistors are in parallel; ask the user to input s if the resistors are in series; output the equivalent resistance for the series or parallel combination of resistors; output an error statement if the user input is not an ‘s or ‘p. . . . Hint: you could use a for-loop (to go through all the resistors in the vector) and either if-statements or switch-statements to test for the different user inputs.

Please use MATLAB to solve this, thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab function Resistance.m

---------------------------------------------------------------------------------------------------------------------

% calculate resistance in series or parallel
function [ ] = Resistance()

res=input('enter resistance in form of row vector : ');
disp('Enter p if resistors are in parallel');
disp('Enter s if resistors are in serial');
n= input('enter your input','s');
R=0;
switch n
case 'p'
for i=1:length(res)
R=R+1/res(i);  
end
R=1/R;
fprintf('Resistance in parallel is %0.2f\n',R);
  
case 's'
for i=1:length(res)
R=R+res(i);  
end
fprintf('Resistance in serial is %0.2f\n',R);
  
otherwise
disp('Error: Wrong input');   

end % end of switch

end

----------------------------------------------------------------------------------------------------------------------------------------------------

Output

MATLAB R2013a PLOTS Seorch Documentation O Preferences Set Path Paralel New Variable Analyze Code Find Files Open Variable ▼

Add a comment
Know the answer?
Add Answer to:
Please use MATLAB to solve this, thanks 7. Write a function M-file that will compute the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. [5pts] Write a MATLAB script that can calculate the equivalent resistance in a circuit that all electrical resis...

    2. [5pts] Write a MATLAB script that can calculate the equivalent resistance in a circuit that all electrical resistors are connected in parallel: . Print the title 'Equivalent Resistance for Resistors Connected in Parallel' on your output. . Check the size of vector resistor to see how many resistors in the circuit. .Check each individual resistance to see any 0 or negative resistance. If there is any, print message 'ERROR', then finish the program. . Otherwise, calculate the equivalent resistance...

  • Use MATLAB to solve this problem. Thank you. Upload the assignment to CANVAS, it should include...

    Use MATLAB to solve this problem. Thank you. Upload the assignment to CANVAS, it should include two things: the PDF and the zipped folder. Late assignments are not accepted. For the questions below, do not create the arrays or matrices by hand. Instead, use built-in MATLAB functions and shorthand notations. Otherwise, no points will be given. 1) Create a function called my product that computes the multiplication of the numbers in any vector using a while loop. The function should...

  • The program has to be written in C The expected output: Please make sure to use...

    The program has to be written in C The expected output: Please make sure to use two-dimensional arrays. OPTIONAL TAKE-HOME QUIZ WORTH 10 POINTS OUT OF A GRAND TOTAL OF 110 FOR THE COURSE A DC electrical circuit consists of an ideal battery with user-suppled terminal voltage VB which drives a resistive load comprised of a user-supplied number m of branches connected in parallel across each other, with each branch consisting of a variable user-supplied number n of resistors and...

  • MATLAN Quiz 2 Create a MATLAB function that calculates the average of values in a vector that als...

    MATLAN Quiz 2 Create a MATLAB function that calculates the average of values in a vector that also drops the slowest values. Call this function average_drop(). The function must have a single input (the vector) and a single output (the average without the lowest score). 1. 2. Create a MATLAB program that asks the user to input grades for a student and calculates the final grade and letter grade. The user must enter 5 quiz grades (worth 50% of the...

  • Task 1 The equivalent resistance Req of four resistors R1, R2, R3 and R4 connected in series is g...

    Use MATLAB to solve these problems, thank u Task 1 The equivalent resistance Req of four resistors R1, R2, R3 and R4 connected in series is given as eq.series R1 R2 R3 R4. The equivalent resistance Req of four resistors R1, R2, R3 and R4 connected in parallel is given as q.parallel K1R2R3 R Write an m-file that does the following in order: Prompt the user for the type of connection (e.g. user should enter "1" for series and "2"...

  • Write your answer code into one function file on matlab

     Write your answer code into one function file on matlab The spiral of Archimedes. The spiral of Archimedes is a curve described in polar coordinates by the equation r= kθ Where r is the distance of a point from the origin, and d is the angle of that point in radians with respect to the origin. Write a function file to compute the spiral of Archimedes with varying number of inputs (no input, one input, two inputs) for k, 0 and varying number of...

  • read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates th...

    read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates the BMI using the equation below, displays the BMI category, and outputs the BMI value tothe user's program W (kg) h2 (m2) BMI Display Normal if 18.5 s BMI 25 Display Overweight if 25 s BMI <30 Display Obese if BMI 2 30 Else display underweight So you will create two...

  • Please use python to write the simple program. Exercise 2 - Summation Write a program to...

    Please use python to write the simple program. Exercise 2 - Summation Write a program to accept integer inputs until the user inputs a non-integer. Then, the program prints the summation of the inputted numbers. Hint: Use the function input() to get the user input. Use a variable total for calculating the summation. Need to use while loop for the repeated inputs. Use if statement with isdigit() function to check whether the user input is an integer or not. if...

  • Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

    Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels. The user-defined function should 1. Receive a single x value as input. 2....

  • matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name...

    matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name the function [max_value, max_index] - LASTNAMES matrix max (x), where input argument x is a vector or matrix (not a scalar), and the outputs are the maximum value(s) and indexes of the maximum value(s) of the mput x. Do not use MATLAB functions max() or find(). Use loops and if branches to determine the maximum elements of matrix. Check for correct number and valid...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT