Background Material Resistors can be made out of many different materials and th
ID: 3349446 • Letter: B
Question
Background Material Resistors can be made out of many different materials and the value of their resistance is expressed in Ohms The value of resistance can be expressed using this formula: Q) where p is resistivity (units 2-cm). L is resistor length (in em) and A is cross-sectional area (in em'). Required Work For the following problem, assume all numbers have units as expressed above. You can resistivity is set to p-100-cm also assume that material a) Write a function named resisi that accepts the resistivity p, length L, and area 4 as input arguments named resist that accepts the resistivity p, length L, and area A as input arguments and s as output arguments the value of resistance and error variable. .The function should work when p. L and A are scalar and when they are vectors. The fiunction itself should not prompt the user for input, and it should not print any values . The function should check that all input arguments are positive in which case error vatiable shoul return set to logical false or 0. If any of the input arguments are negative or equal to zero the error variable should be set to logical true or l b) Write a script that satisfies these criteria: Prompt the user for the length L of one or more resistors. Store them in a vector. Prompt the user for the cross-sectional area A of one or more resistors. Store them in a vector. Invoke the resist function and pass the , L and vectors to t . · alue of the error variable is true" display a message "Your data is negative or equal to zero" If the value of the error variable is "false" then print out the values of p. L, A and the calculated resistance using a for loop (optional practice: use while loop instead). If you computer is Microsoft Windows based, store your -m file s) in C: Itemp Sample test data for verifying your results: Suppose the user enters 10, 30, and 80 for the lengths and 1, 2, and 2.5 for the areas Your output should look similar to the following table. Note: You are not required to print out the text labels above each column Enter length values [10 30 80] Enter area values [1 2 2.5] 10.00 10.00 1.00 100.00 10.00 30.00 2.00 15e.00 10.00 80.00 2.50 320.00Explanation / Answer
For the part 1 Write the following code in MATLAB m file:
function [R,e] = resist(p,l,a); %the function is defined
R=zeros(1,length(l)); % dimension of R is defined in terms of elements of l
for i=1:length(l)
if p(i)<0 |l(i)<0|a(i)<0 % condition is put if user give any negative value vector
e=1; % error variable become 1 if user give any negative value vector
disp('error');
else
R(i)=(p(i)*l(i)/a(i));
e=0;
end
end
end
Result of part 1:
Run the code and type this in Matlab command by giving p,l,a in vector form
if user enters negative value than for this type this in matlab command
resist(-2,-3,-4)
Just test for other values after running the file and caling function resist(p,l,a) in matlab command promt you will get desried result.
For the part 2 Write the following code in MATLAB m file:
l=input('enter the value of length in cm ='); % take the value from user
p=input('enter the value of length in ohm cm ='); % ohm centimeter
a=input('enter the value of area in cm^2 =');
function [R,e] = resist(p,l,a);
R=zeros(1,length(l));
for i=1:length(l)
if p(i)<0 |l(i)<0|a(i)<0
e=1;
disp('your data is negative or equal to zero');
else
R(i)=(p(i)*l(i)/a(i));
fprintf('the value of resistance is = %d ohm ',R(i));
fprintf('the value of lenght is= % cm ',l(i));
fprintf('the value of area is = %d cm^2 ',a(i));
e=0;
end
end
end
REsult for pasiing values
after this value input type this in command promt
if user enters negative value than for this type this in matlab command
after this value input type this in command promt
NOTE : the 0 here signifies that for that value either of (p,l,a) passed by user is negative.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.