Write a program in Matlab where the program plays a hot and cold game. The user
ID: 3576476 • Letter: W
Question
Write a program in Matlab where the program plays a hot and cold game. The user answers two inputs: x=input('what is the x location of the object?') y=input('what is the y location of the object?') You write the program so that the computer plays the game. *Start with a 20 by 20 matrix.* Pick a starting point. Calculate the distance to the object. Pick another point, calculate the distance to the object. Asking only which point was closer, you pick your next location and calculate distance. Keep going until distance is less than .5
Explanation / Answer
disp("what is x location of object: ");
x = input();
disp("what is y location of object: ");
y = input();
x1 = rand(20);
y1 = rand(20);
x2 = rand(20);
y2 = rand(20);
d1 = [x,y;x1,y1];
d2 = [x,y;x2,y2];
while distance < 5
distance1 = pdist(d1,'euclidean');
distance2 = pdist(d2,'euclidean');
if (distance1 < distance2):
nextPoint = [x1, y1]
end
else:
nextPoint = [x2, y2]
end
nextPoint = [x2, y2]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.