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

The problem is to create a program in MATLAB in GUI or GUIDE to simulate a baske

ID: 3852662 • Letter: T

Question

The problem is to create a program in MATLAB in GUI or GUIDE to simulate a basketball shooting game. The question now is to edit the code to show the parabola of the ball to determine whether it goes in or not.

I already have the following

function parabola()
   fprintf ('WELCOME TO THE GAME ');
   fprintf ('Choose distance of the basket: ');
   fprintf ('1. 25m 2. 40m ');
   distance = input('Enter 1 or 2: ');
   u = input('Enter the initial velocity of the basketball: ');
   a = input('Enter the angle at which you want to shoot: ');
  
   % calculate the range
   R = (u*u)*sin(2*a);
   R = R/9.8;
  
   if (R == distance)
       fprintf (' You have won!');
   else
       fprintf (' Sorry, better luck next time.');
   end
end

Explanation / Answer

Matlab Code :
% Feel free to comment if u have doubt
% Program starts :-)

   fprintf ('WELCOME TO THE GAME ');
   fprintf ('Choose distance of the basket: ');
   fprintf ('1. 25m 2. 40m ');
   d = input('Enter 1 or 2: ');
  
   switch(d)
   case 1
   distance = 25;
   fprintf ('selected distance : 25 m ');
   case 2
   distance = 40;
   fprintf ('selected distance : 40 m ');
   otherwise
   distance = 25;
   fprintf('Default distance selected ' );
   end
  
u = input('Enter the initial velocity of the basketball: ');
a = input('Enter the angle at which you want to shoot: ');

x0 = 0; %initial U
y0 = 0; %initial V
g = 9.81;

%calculate t_flight
        b = u*sin(pi*(a/180));
        x = -g/2;
        y = y0;
        t_flight = (-b-sqrt(b^2-4*x*y))/(2*x);
        
%calculate range
  range = ((u*cos(pi*(a/180))*t_flight));

%calculate v_impact
  vx = u*cos(pi*(a/180));
  vy = -g*t_flight+u*sin(pi*(a/180));
  v_impact = sqrt(vx^2+vy^2);

%draw the projectile
  t = linspace(0,t_flight,30);
  xdot0 = u*cos(pi*(a/180));
  ydot0 = u*sin(pi*(a/180));
  x = xdot0*t+x0;
  y = -(g/2)*t.^2+ydot0*t+y0;
  plot(x,y)
  xlabel(sprintf('Distance (m) - Range = %5.3f',range));
  ylabel('Height (m)');
  
range = int16(range);
distance = int16(distance);


if (range == distance)
   fprintf (' You have won!');
else
   fprintf (' Sorry, better luck next time. ');
end