MATLAB Write a function named rparallel which computes the e
[MATLAB] Write a function named r_parallel which computes the equivalent resistance and power rating for a network consisting of resistors connected in parallel. The function arguments are two row vectors (of equal length, length1), the first containing resistance values and the second containing corresponding power ratings. The function returns two values, equivalent resistance and power rating. Note that the equivalent power rating is determined by the worst-case resistor, the one that first reaches its power rating. Hint: when the parallel resistor network is operating at its maximum power rating there is at least one resistor which is operating at exactly its maximum power rating, there may be one or more resistors operating at less than their maximum power rating, and none of the resistors are operating above their maximum power rating. Test the function on the following two examples and show the results (your output format may be slightly different than shown in the example).
> [r_eq,p_eq] = r_parallel([10 10 10],[5 5 5])
r_eq = 3.3333
p_eq = 15.000
> [r_eq,p_eq] = r_parallel([10 20 20],[5 4 3])
r_eq = 5
p_eq = 42.000
Unit tests are a valuable tool for verifying program integrity. Write a script to test the r_parallel function. Use the assert command (see MATLAB help) and see the article Write Script-Based Unit Tests for examples of how it can be used. Include three test cases, all different from those given above. Hint: because floating-point computations are not exact you may need to include a tolerence, e.g. instead of the test result==expected_result you might need to perform a test such as abs(resultexpected_result)<1e9 when checking the function results (be sure to choose an appropriate tolerence).
Solution
MATLAB script of the function is as below:
function [r_eq, p_eq]=r_parallel(r, power)
%calculation of r_eq
r_eq=0;
for i=1:length(r);
r_eq=r_eq+1/r(i);
end
r_eq=1/r_eq;
%calculation of r_eq
%in parallel circuit maximum current flows thru smallest r
ind=find(r==min(r));
%voltage which generate maximum current
for i=1:length(ind)
V(i)=sqrt((power(ind(i))*r(ind(i))));
end
V=min(V);
%the voltage will be same across all resistances in parallel
%p_eq = P1+P2+P3
p_eq=0;
for i=1:length(power)
p_eq=p_eq+V^2/r(i);
end
end
OUTPUT 1:
[r_eq p_eq]=r_parallel([10 10 10], [5 5 5])
r_eq =
3.3333
p_eq =
15
OUTPUT 2:
[r_eq p_eq]=r_parallel([10 20 20], [5 4 3])
r_eq =
5
p_eq =
10
![[MATLAB] Write a function named r_parallel which computes the equivalent resistance and power rating for a network consisting of resistors connected in parallel [MATLAB] Write a function named r_parallel which computes the equivalent resistance and power rating for a network consisting of resistors connected in parallel](/WebImages/4/matlab-write-a-function-named-rparallel-which-computes-the-e-981056-1761503605-0.webp)
![[MATLAB] Write a function named r_parallel which computes the equivalent resistance and power rating for a network consisting of resistors connected in parallel [MATLAB] Write a function named r_parallel which computes the equivalent resistance and power rating for a network consisting of resistors connected in parallel](/WebImages/4/matlab-write-a-function-named-rparallel-which-computes-the-e-981056-1761503605-1.webp)