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

1) Write the MATLAB code to generate a random number between 1 and 3 using the r

ID: 642818 • Letter: 1

Question

1) Write the MATLAB code to generate a random number between 1 and 3 using the randi function. You can find more information about randi at AWWA mathworks co helplmatlabl refrandi.html 2) Consider the Monty Hall problem mhose not familiar can find it here: http:/L en.wikipedia.org/wiki/Monty Hall problem or watch the following video until 1:07 http:ll www youtube.com/watch? mhl eGIGg a) write the pseudo-code to ask the user which door they would like to initially choose. Also write the code to pick the winning door at random (Hint: store these in variables named initial choice and winning door) b) Based on your solution to part A, write the pseudo-code to determine which door is revealed to the user as a goat. Store the revealed door number in a variable named revealed door. c write the pseudo-code for the final decision to ask if the wants to change doors, and then reveal user Store whether or not they won a car or response in a variable named change door. You can expect the user's response for for no. Determining whether they win or lose will depend on the initial choice, winning door and change door values

Explanation / Answer

1) randi(3)

2) The entire code is as follows:

clc
clear all

door = [0,0,0];

initial_choice = input('Enter your chosen door number (1-3) : ');
winning_door = randi(3);

door(initial_choice)=1;
door(winning_door)=1;

if(door(1)==0)
    revealed_door=1;
else if(door(2)==0)
        revealed_door=2;
    else
        revealed_door = 3;
    end
end

disp([ 'There is a goat behind door number ' num2str(revealed_door)]);

change_door = input('Do you want to change your chosen door? (y/n) : ','s');

door=[0,0,0];

door(initial_choice)=1;
door(revealed_door)=1;

if(change_door== 'y')
    if(door(1)==0)
        initial_choice=1;
    else if(door(2)==0)
            initial_choice=2;
        else
            initial_choice=3;
        end
    end
end

if(initial_choice==winning_door)
    disp('Congratulations ! You won a car !');
else
    disp('Sorry! You won a goat!');
end