MATLAB Programming 2 Electrical resistors are said to be con

MATLAB Programming:

2. Electrical resistors are said to be connected \"in series\" if the same current flows through each of them and \"in parallel\" if the same voltage is applied across each. If in series, they are equivalent to a single resistor whose resistance is given by:

R = r1 + R2 +R3 + R4 + R5..... + Rn

If in parallel, their equivalent resistance is given by :

1/R = 1/R1 + 1/R2 + 1/R3 + 1/R4 + 1/R5..... + 1/Rn

Write an m-file that prompts the user for the type of connection (series or parallel) and the number of resistors n and then computes the equivalent resistance (assume the individual resistances are 2 ohms). Use switch statement for the connection and for loop for the resistance calculation.

Solution


% The script starts here

clc;
clear all ;

prompt = \' series or parallel ? \';

connection = input(prompt, \'s\');

prompt = \' number of resistors ? \';

n = input(prompt);

switch lower(connection)
   case {\'series\'}
       R = n*2;
       disp(\'equivalent resistance of series combination is \');
      disp(R)
   case \'parallel\'
       R = 2/n;
       disp(\'equivalent resistance of parallel combination is\');
      disp(R);
     
   otherwise
      disp(\'please check your spelling of series or parallel\')
end


% The script ends here

MATLAB Programming: 2. Electrical resistors are said to be connected \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site