Question

In: Advanced Math

Create a hot and cold game in Matlab to find a point in an (X,Y) 2D...

Create a hot and cold game in Matlab to find a point in an (X,Y) 2D coordinate plane. The user answers two inputs: x=Input('x') y=Input('y'). THE INPUTS WILL ONLY BE INTEGERS FROM 0 TO 100. This means no negative numbers. You write the program so the computer plays the game. The computer must play the game (comparing distances only) and give the same point as the user inputs. To keep it simple the code will check distances until distance = 0 (right on the point). certain section can be eliminated by comparing distances. You will use mostly loops and if-then statements. ONLY PROMPT THE USER TO INPUT THE "SECRET" X AND Y LOCATION once. THE COMPUTER WILL FIND THE POINT. DO NOT KEEP PROMPTING THE USER TO KEEP GUESSING.

Solutions

Expert Solution

%Matlab code for hot and cold game
clear all
close all
%promt for inital x and y
prompt1 = 'What is the value of x? ';
x = input(prompt1);

prompt2 = 'What is the value of y? ';
y = input(prompt2);

%initial search range for x and y
a1=0; b1=100;
a2=0; b2=100;

%initialize loop
dist=10; it=0;
while dist~=0
    it=it+1;
    x1= randi([a1 b1],1);
    y1= randi([a2 b2],1);
  
    dist=sqrt((x-x1)^2+(y-y1)^2);
  
    if x<x1
        b1=x1;
    else
        a1=x1;
    end
  
    if y<y1
        b2=y1;
    else
        a2=y1;
    end
    fprintf('\tAfter %d iteration x=%d and y=%d\n',it,x1,y1)
end
fprintf('Hence the secret location is %d and %d\n',x1,y1)
%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%
      
   


Related Solutions

Write a program in Matlab where the program plays a hot and cold game. The user...
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. Pick a starting point. Program Calculates the distance to the object. Program picks another point, calculates the distance to the object. Program knows its at the right spot when the distance is less than...
(In Matlab) Create a base class named Point that has the properties for x and y...
(In Matlab) Create a base class named Point that has the properties for x and y coordinates. From this class derive a class named Circle having an additional property named radius. For this derived class, the x and y properties represent the center coordinates of a circle. The methods of the base class should consist of a constructor, an area function that returns 0, and a distance function that returns the distance between two points. The derived class should have...
Using matlab Find x and y that solve the following system: ln(x 2 + y) =...
Using matlab Find x and y that solve the following system: ln(x 2 + y) = 1 − y , xy = − √ x
Find the point on the curve y=4x+4 closest to the point (0,8) (x,y)=
Find the point on the curve y=4x+4 closest to the point (0,8) (x,y)=
Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
Use MuPAD to find the point on the line y = 2 – x/3 that is closest to the point x = -3, y = 1.
Use MuPAD to find the point on the line y = 2 – x/3 that is closest to the point x = -3, y = 1.  
Find the vector equation of the tangent line to the surface f(x, y)=x/(1+y)+e^(x+y) at the point...
Find the vector equation of the tangent line to the surface f(x, y)=x/(1+y)+e^(x+y) at the point (-1,1,1/2) that is parallel to the xz-plane
Given the funtion g(x,y) = (e^x)(y)+sin(x/y). 1. Find the linearization of g(x,y) at the point (1,2)....
Given the funtion g(x,y) = (e^x)(y)+sin(x/y). 1. Find the linearization of g(x,y) at the point (1,2). 2. Estimate the value of g(1.01, 1.99).
Consider a sheet of 2d graphene in the x-y plane. The 2d sheet of graphene i...
Consider a sheet of 2d graphene in the x-y plane. The 2d sheet of graphene i then sut into a ribbon in the x direction. The energy becomes quantizes in the y direction. calcualte the  charge carrier energies E as a function of kx and ky.
Find the coordinates of the point (x, y, z) on the plane z = 4 x...
Find the coordinates of the point (x, y, z) on the plane z = 4 x + 1 y + 4 which is closest to the origin.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT