1 if statements

Begin by creating a script named q1.m and copy the following Matlab code into the script:

% q1.m 

% (a) Answer part (a) below this comment



% (b) Answer part (b) below this comment



% (c) Answer part (c) below this comment 


(a) [5 marks]

A passing grade for this test is 50 percent or better.

Assume that a student’s grade is stored in a variable named grade (you may create such a variable but you are not required to do so). Write an if or if-else statement that sets the value of a variable named pass to 1 if the student has a passing grade and sets pass to 0 if the student does not have a passing grade.

(b) [5 marks]

As a quality control engineer at a food packaging plant you need to program your packaging equipment to reject packages that weigh less than 495 grams and more than 505 grams.

Assume that the weight of the package is stored in a variable named wt (you may create such a variable but you are not required to do so). Write an if or if-else statement that sets the value of a variable named rejected to 1 if the package should be rejected and sets rejected to 0 if the package should not be rejected.

(c) [5 marks]

Consider the rectangle shown in the figure below:

Assume that you are given a point \(p\) having an x-coordinate px and a y-coordinate py (you may create variables px and py but you are not required to do so). Note that in the figure the point \(p\) is outside of the rectangle.

Write an if-elseif statement that sets the value of a variable named location to:

  • 0 if \(p\) is outside of the rectangle
  • 1 if \(p\) is inside of the rectangle (in the gray area of the figure)
  • 2 if \(p\) is on the perimeter of the rectangle (on the black line of the border of the rectangle)