Question: Matlab only % First, use the function watermelon_target to get the x location of your % target. This will open up a figure, but hold

Matlab only

% First, use the function watermelon_target to get the x location of your

% target. This will open up a figure, but "hold on" hasn't been issued

% yet - be sure to do that before you plot!

x = randi([50, 150]);

plot([1 150], [0 0], 'k-')

hold on

plot(x, 0, '.r', 'MarkerSize', 10)

plot(x, 0, 'or', 'MarkerSize', 12)

plot(x, 0, 'or', 'MarkerSize', 22)

plot(0,0,'.', 'MarkerSize', 40, 'Color', [0 .5 .1])

plot(0,0,'*g', 'MarkerSize', 10)

T = text(0,0,'Y');

set(T, 'FontSize', 20);

hold off

% Now that you have the x location of your target, and see the target on

% your screen, ask the user for an angle (in degrees) and a velocity (in

% meters per second). Your user should get three trys to hit the target

% with the watermelon. Use a for loop to provide these three tries, and

% use input to get each of the angle and speed. Wait a second, don't you

% mean "velocity?" Nope, remember that velocity is a vector, while speed is

% a directionless magnitude. We want to know the mangitude of the change

% in distance over time, without an x or y specific component.

% get the user specified angle and speed

% get the initial angle

% convert degrees to radians

% get the initial velocity

% define your constant of gravity

% identify the total flight time

% now do a loop, from time zero to the t_total, in steps of 100ths of a

% second. This is "launching the watermelon"

% calculate the current x_t and y_t, for this given t

% plot the watermelon location with a green dot

% use pause to "pause" the loop for 0.01 second, so the plot shows

% everything in "real time."

% use an if statement to see if the player hit (but allow a tolerance of 2 meters)

% if they "hit" tell them

% and then move the target for the remaining trys

% do you need to turn hold on again after calling the

% watermelon_target? Look inside watermelon_target to see if "hold

% off" is issued towards the end.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!