Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Solve the following problems using MATLAB and include solutions(D, the functi

ID: 3603650 • Letter: 1

Question

1. Solve the following problems using MATLAB and include solutions(D, the function code(2) and the contents (3) of your workspace in your single document on blackboard R1 R7 C2 Vs C3 Vs C5 round R5 R2 a. Write a function that combines two parallel resistors and returns the combined value i. Restate the problem and paste the script into your final write-up b. Write a function that combines two series resistors and returns the combined value Restate the problem and paste the script into your final write-up ii. Evaluate the combined Resistance (Req) in the following circuit using the function you defined in (la,1b) c. ii. R2-12 ii R3- (last two digit of your ID+3)2 iv. R4 = 3 v. R5 (last two digit of your ID + 6) 2 vi. R6-5 vii If you don't want to see the answer twice you need to add a semicolon

Explanation / Answer

ANSWER::

clc
%-- resistance INPUTS/calls --g
resistance_call = input('What is the resistance wanting to be achieved?: ','s');
thousand_set = '[kK]';
million_set = '[mM]';
r_set = 'rR';
var = 'kKmM0123456789.';
non_r = [];
non_l = [];
thousd = '.*1000';
mill = '.*1000000';
digits = '0123456789.';

for count = 1 : length(resistance_call);
x = resistance_call(count);
if strfind(r_set, x);
else
non_r = [non_r count];
end;  
end

resistance_array = ([resistance_call(non_r)]);
resistance_array_call_final = str2num(resistance_array);

for count2 = 1:length(resistance_array);
x = resistance_array(count2);
if strfind(var, x)
else
disp('ERROR:2 (refer to manual)');
return;
end

end

end_count = 0;

for count3 = 1:length(resistance_array);
x = resistance_array(count3);
if strfind(thousand_set, x)
if end_count == 1
disp('ERROR:3 (refer to manual)');
return;
elseif length(resistance_array) == count3
resistance_array = regexprep(resistance_array, thousand_set, '.*1000', 'ignorecase');
resistance_array_call_final = str2num(resistance_array);
end_count = end_count + 1;
elseif length(resistance_array) ~= count3
temp_array = regexprep(resistance_array, thousand_set, '.', 'ignorecase');
temp2_array = str2num(temp_array);
resistance_array_call_final = temp2_array.*1000;
end_count = end_count + 1;
end
elseif strfind(million_set, x)
if end_count == 1
disp('ERROR176 refer to manual');
return;
elseif length(resistance_array) == count3
resistance_array = regexprep(resistance_array, million_set, '.*1000000', 'ignorecase');
resistance_array_call_final = str2num(resistance_array);
end_count = end_count + 1;
elseif length(resistance_array) ~= count3
temp_array = regexprep(resistance_array, thousand_set, '.', 'ignorecase');
temp2_array = str2num(temp_array);
resistance_array_call_final = temp2_array.*1000;
end_count = end_count + 1;
end
end
end

if resistance_array_call_final == 0;
disp('You wont need any resistors for that!');
return
else
end

int_resis_msg = sprintf('Resistance: %10.4f Ohm/s',resistance_array_call_final);
disp(int_resis_msg);

%-- resistor amount INPUTS/calls --
amount_call = input('What is the maximum amount of resistors allowed?: ', 's');

for count = 1:length(amount_call);
x = amount_call(count);
if strfind(digits, x)
else
disp('ERROR:5 (refer to manual)');
return;
end

end

amount_restistors = str2num(amount_call);

if amount_restistors >= 10
disp('ERROR:6 (refer to manual)');
return;
elseif amount_restistors ~= round(amount_restistors);
disp('ERROR:7 (refer to manual)');
return;
else
end

%-- resistance arrays --
resistors = [...
10000000 8200000 6800000 5600000 4700000 3900000 3300000 2700000 ...
2200000 1800000 1500000 1200000 1000000 820000 680000 560000 470000 ...
390000 330000 270000 220000 180000 150000 120000 100000 82000 68000 ...
56000 47000 39000 33000 27000 22000 18000 15000 12000 10000 8200 ...
6800 5600 4700 3900 3300 2700 2200 1800 1500 1200 1000 820 680 560 ...
470 390 330 270 220 180 150 120 100 82 68 56 47 39 33 27 22 18 15 ...
12 10 8.2 6.8 5.6 4.7 3.9 3.3 2.7 2.2 1.8 1.5 1.2 1];

array = rot90(resistors);

%-- series --

totalval=resistance_array_call_final;
temp=zeros(amount_restistors,1);

for n =1:amount_restistors ;
for k = 1:length(array); %'k' is created as a new variable so that values can be stored following the length of 'array'.
if array(k)-resistance_array_call_final >0 ; %This value of k which was stored is then subtracted from the total resistance value entered by the user and is checked if it is greater than zero.
temp(n) = array(k-1); %A temporary variable is then created. This variable is created on the basis of what 'array)k-1) is. This value is copied into a new array.
break
end
end
resistance_array_call_final = resistance_array_call_final-temp(n); %The resistor value changes to the new value which needs to be worked out and therefore repeating the loop till all conditions are satisfied
if resistance_array_call_final <1;
break
end
end

%-- messages --
p = 0;

for a = 1:amount_restistors;
if temp(a,1) > 0;
message1=sprintf('Resistor %g is %g Ohm''s',a,temp(a,1)); %This 'sprintf' command is used to display the resistor values used in the calculations. But only the number used, not the maximum amount that could have been used
disp(message1);
p = p+1;
elseif temp(a,1) < 0;
message1=sprintf('Resistor %g is %g Ohm''s',a,temp(a,1)); %This 'sprintf' command is used to display the resistor values used in the calculations. But only the number used, not the maximum amount that could have been used
disp(message1);
p = p+1;
elseif temp(a,1) == 0;
message2=sprintf('Resistor %g is not required as more accurate value is obtained using %g resistor/s',a,p);   
disp(message2);
end
end

message4=sprintf('Overall achieved resistance: %10.4f Ohm/s',sum(temp));
disp(message4);

if totalval-sum(temp) ~= 0;
message2 = sprintf('The error rate is %g percent',abs(totalval-sum(temp))/totalval*100);
disp(message2);
elseif totalval-sum(temp) == 0; %This whole 'if' loop is used to calculate the percentage error that occurs in the calculations. It displays the error if there one, or displays a 100% match statement if the resistors used are exact.
message3 = sprintf('100 percent match, use the above resistors in series');
disp(message3);
end