You are analyzing a machine that uses three different switches (SW1, SW2, SW3).
ID: 3799184 • Letter: Y
Question
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=0Explanation / Answer
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)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.