Matlab assignment:( I just the code please ) 1. Create a function file that acce
ID: 2249622 • Letter: M
Question
Matlab assignment:( I just the code please )1. Create a function file that accepts three inputs, inVar1, inVar2, inVar3. inVar1 specifies whether you want to calculate the time, capacitance, or resistance (i.e. ‘time’, ‘cap’, ‘res’) of an astable 555 timer circuit, and inVar2 and inVar3 specify the other parameters needed to calculate the required parameter (i.e. if inVar1 is ‘cap’, inVar2 could be time and inVar3 could be resistance). Resistance can be equal to R1 + R2. The function should have a single output which is the result of the calculation requested.
Matlab assignment:( I just the code please )
1. Create a function file that accepts three inputs, inVar1, inVar2, inVar3. inVar1 specifies whether you want to calculate the time, capacitance, or resistance (i.e. ‘time’, ‘cap’, ‘res’) of an astable 555 timer circuit, and inVar2 and inVar3 specify the other parameters needed to calculate the required parameter (i.e. if inVar1 is ‘cap’, inVar2 could be time and inVar3 could be resistance). Resistance can be equal to R1 + R2. The function should have a single output which is the result of the calculation requested.
1. Create a function file that accepts three inputs, inVar1, inVar2, inVar3. inVar1 specifies whether you want to calculate the time, capacitance, or resistance (i.e. ‘time’, ‘cap’, ‘res’) of an astable 555 timer circuit, and inVar2 and inVar3 specify the other parameters needed to calculate the required parameter (i.e. if inVar1 is ‘cap’, inVar2 could be time and inVar3 could be resistance). Resistance can be equal to R1 + R2. The function should have a single output which is the result of the calculation requested.
Explanation / Answer
Matlab Script:
function op = timer555(invar1,invar2,invar3)
%using the formula %T1 = 0.69*(R1+R2)*C
if strcmp(invar1,'time')
%with the available inputs capacitance and R1+R2 we can calculate only
%high time
op = 0.69*invar2*invar3;
elseif strcmp(invar1,'cap')
op = (1/0.69)*invar2/invar3;
elseif strcmp(invar1,'res')
op = (1/0.69)*invar2/invar3;
else
error('invalid input invar1');
end
end
command window output:
>> clear all
>> op = timer555('time',1000,10^-6)
op =
6.9000e-004
>> op = timer555('cap',10^-4,1000)
op =
1.4493e-007
>> op = timer555('res',6.9*10^-4,10^-6)
op =
1.0000e+003
>> op = timer555('ind',6.9*10^-4,10^-6)
??? Error using ==> timer555 at 12
invalid input invar1