You are analyzing a machine that uses three different switch

You are analyzing a machine that uses three different switches (SW1, SW2, SW3). The switches are connected to a light bulb, but only certain combinations of these switches will turn the light bulb on. The combinations are given in the table below. (1 = electricity can flow, 0 = no flow) Ask the user for the state of each switch. Then tell the user corresponding state of the light bulb. Create an anonymous function (accepting 3 inputs) where you use logical operators to determine and return the state of the light bulb SW1=1 SW2=1 SW3=0 SW1=0 SW2=1 SW3=1 SW1=1 SW2=0 SW=0

Solution

prompt = \'state of switch s1 in binary \';
s1 = input(prompt);

prompt = \'state of switch s2 in binary \';
s2 = input(prompt);


prompt = \'state of switch s3 in binary \';
s3 = input(prompt);

%anonumous function bulb which takes 3 arguments a,b,c and evaluates expression a and b or c

bulb = @(a,b,c) a&b|c ;

statusofbulb=bulb(s1,s2,s3)

 You are analyzing a machine that uses three different switches (SW1, SW2, SW3). The switches are connected to a light bulb, but only certain combinations of th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site