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

1. (4 points) Understand and correct MATLAB conditions. For these problems you d

ID: 3814176 • Letter: 1

Question

1. (4 points) Understand and correct MATLAB conditions. For these problems you do not need to write entire matlab functions or scripts, just the condition statements requested. la. Write a selection statement that will print "warm' ifthe temperature is between 80 and 90, inclusive. lb. Write a selection statement that will print hot' if the temperature 80, 'pleasant' if the temperature 60, 'cool' if the temperature is 45, 'cold' otherwise. lc. If integer variable currentNumber is odd, change its value so that it is now 3 times currentNumber plus 1, otherwise change its value so that it is now half of currentNumber ld. Find the largest of three scalar numbers x y and z and assign the value to the variable largest.

Explanation / Answer

%1a
if temperature>= 80 && temperature<=90 %simple if statement
    disp('warm'); %disp() used to display text on screen
end

%1b
if temperature>= 80 %simple if else staircase
    disp('warm');
elseif temperature>= 60 %note that elseif is single word, and not spaced
    disp('pleasant');
elseif temperature>= 45
    disp('cool');
else
    disp('cold'); %comes under else condition
end

%1c
if mod(currentNumber, 2) == 1 %mod(x,y) finds the remainder after dividing x by y
    currentNumber = 3*currentNumber + 1; %change as required for odd number
else
    currentNumber = currentNumber/2; %change as required for even number
end

%1d
if x > y %first compare two vairable
    if x > z %then compare the largest with the third varialbe
        largest = x;
    else
        largest = z;
    end
else %here y is larger than x
    if y > z %so compare z with y
        largest = y;
    else
        largest = z;
    end
end

I tried my best to keep the code simple. As a bonus, I also commented the code for better understanding. If you face any dificulty eiththis, please let me know in the comment section. I shall be glad to help you.