Bonus. Modify (1) to include a fourth input variable and a second output variabl
ID: 2249568 • Letter: B
Question
Bonus. Modify (1) to include a fourth input variable and a second output variable. inVarl should be the same as (1), an indication of what calculation the function should perform. 1) 2) inVar2, inVar3, and inVar4 should be: a. If finding time 3 input variables should be R1, R2 and C (order doesn't matter). ii. i. Outputs should be time and duty cycle. b. If finding resistance i. 3 input variables should be C, time, and duty cycle. i. Outputs should be R1 and R2. c. If finding capacitance 2 i. li. 3 input variables should be Time, R1 and R2 Output should be C and duty cycle.Explanation / Answer
Matlab Script:
function [op1 op2] = timer555_mod(invar1,invar2,invar3,invar4)
%T(time) = 0.69*(R1+(2*R2))*C
%High time = 0.69*(R1+R2)*C
if strcmp(invar1,'time')
%invar2 R1
%invar3 R2
%invar4 C
%op1 time
%op2 duty cycle
%op1 is total time
op1 = 0.69*(invar2+(2*invar3))*invar4;
%high time = 0.69*(R1+R2)*C
TH = 0.69*(invar2+invar3)*invar4;
op2 = 100*TH/op1;
%T1 = 0.69*(R1+2R2)*C
elseif strcmp(invar1,'cap')
%invar2 time
%invar3 R1
%invar4 R2
%op1 Capacitance
%op2 duty cycle
op1 = (1/0.69)*invar2/(invar3+(2*invar4));
TH = 0.69*(invar3+invar4)*op1;
op2 = 100*TH/invar2;
elseif strcmp(invar1,'res')
%invar2 time
%invar3 capacitance
%invar4 duty cycle
%Ax = b
v1 = (1/0.69)*invar2/(invar3);%this is R1+2R2;
v2 = (1/0.69)*(1/invar3)*invar5*invar4/100;%this is R1+R2
A = [1 2;1 1];%R coefficients
b = [v1;v2];
op = A;
op1 = op(1);
op2 = op(2);
else
error('invalid input invar1');
end
end
command window output:
>> clear all
>> [op1 op2] = timer555_mod('time',1000,2000,10^-6)
op1 =
0.0034
op2 =
60.0000
>> [op1 op2] = timer555_mod('cap',0.00345,1000,2000)
op1 =
1.0000e-006
op2 =
60.0000
>> [op1 op2] = timer555_mod('res',0.00345,10^-6,60)
op1 =
1000
op2 =
2.0000e+003
>>