Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The purpose of this assignment is to review the basic capabilities and propertie

ID: 3877926 • Letter: T

Question

The purpose of this assignment is to review the basic capabilities and properties of Matlab and to prepare for writing code in EmbeddedC. You should: Plan your solutions (e.g., HW02-1 and HW02-3) Document your plan for each solution using a flowchart or pseudo-code Submit each plan as a separate file (HW02-1.io, or HW02-1.ppt, or HW02-1.txt, etc.) o o Document each Matlab function (e.g., HW02-2 and Hw02-4) before your enter it and as you debugi . Use Matlab comments as needed, The comments should explain the meaning or usage of variables and major sections of code. Line-by-line comments may not be completely necessary. o o o Include the "ENGRil/ENGR112 Script Standard Header" at the beginning of each Matlab file as listed below:

Explanation / Answer

HW02-1

1) Initialize loop counter variable "counter" to 0

2) The control moves to an infinite loop

3) Within each iteration of infinite loop increment the value of counter by 1

4) If counter is a multiple of 4 then turn on LED1 else turn off LED1.

HW02-2

condition = true; % A boolean variable that starts as true
counter=0; % Counter set to 0
LED1=false; % LED 1 is initially off
while condition % Infinite loop
counter=counter+1; % counter is incremented by 1 every iteration
if rem(counter,4)==0 % if counter is a multiple of 4 turn on LED1 else turn it off
LED1=true;
else
LED1=false;
end
disp(counter); % diagnostic display of counter and LED 1 values
disp(LED1);
if counter>1000 % Stopping criteria - Loop stops after 1000 iterations ( else it will loop indefinitely
condition=false;
end
end

HW02-3

1) Initialize loop counter variable "counter" to 0

2) Initialize LED1 "oncounter" to 0

3) Initialize LED1 "offcounter" to 0

4) Initialize LED1 to true

5) The control moves to an infinite loop

6) Within each iteration of infinite loop increment the value of counter by 1 and if LED1 is true then increase oncounter by 1 but if LED1 is false then increase offcounter by 1.

7) If then set oncounter to 0 and LED1 to false

8) if offcounter==4 then set offcounter to 0 and LED1 to true

HW02-4

condition = true; % A boolean variable that starts as true
counter=0; % Counter set to 0
% No. of iterations for which LED1 is on
offcounter=0;   % No. of iterations for which LED1 is off
LED1=true; % State of LED1 - Initially on
while condition % Infinite loop
counter=counter+1;
disp(counter);
disp(LED1);
if LED1

% if LED 1 is on increment the oncounter. If oncounter >=3 set oncounter to 0 and turn off LED1
> if oncounter>=3
> LED1=false;
end
else

% if LED 1 is off increment the offcounter. If offcounter >=5 set offcounter to 0 and turn on LED1

offcounter=offcounter+1
if offcounter>=5
offcounter=0;
LED1=true;
end

end
  
if counter>20 % Execution of infinite loop iis stopped after 20 iterations for analysis
condition=false;
end
end