You are analyzing a machine that uses three different switches (SW1, SW2, SW3).
ID: 642024 • 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)
SW1
SW2
SW3
Light Bulb
0
0
0
0
0
0
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
1
1
1
0
1
1
1
1
1
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. Note: DO NOT over complicate this task. No
SW1
SW2
SW3
Light Bulb
0
0
0
0
0
0
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
1
1
1
0
1
1
1
1
1
Explanation / Answer
%This creates the anonymous function
myfunction = @(SW1,SW2,SW3) (SW3==1 | SW1|SW2==1);
SW1 = input('Enter the state of switch 1 (1=flow, 0=no flow): ');
SW2 = input('Enter the state of switch 2 (1=flow, 0=no flow): ');
SW3 = input('Enter the state of switch 3 (1=flow, 0=no flow): ');
Light = myfunction(SW1,SW2,SW3);
fprintf('The state of the light bulb is %i ',Light);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.