# Question: i need some help with my matlab code please ...

###### Question details

I need some help with my MatLab code please. . . The requirements for this project are:

Use a "for" loop or a "while" loop to propagate the projectile in 0.01 second time steps all the way until impact. Mark the impact spot with a marker and display the impact coordinates on the projectile/terrain plot. Label the axes accordingly and give your figure a title. While keeping the initial velocity constant, "experimentally" determine the initial angle of the projectile with respect to the horizontal in order to achieve maximum range.

I really need help with changes to my existing code that will stop the projectile at the intersection with the ground, and projecting the distance the projectile has travelled with each change of angle. My existing code is as follows:

clear all

close all

clc

init_velocity=200; %m/s

init_angle=50; %degrees

angle=(init_angle);

u=init_velocity;

g=9.8; %accelaeration due to gravity

t=[0:0.01:40]; %time array

vx=init_velocity*cosd(angle);

x=vx*t;

vy=init_velocity*sind(angle);

y=g/2*t.^2+vy*t;

T_hit=(2*u*sind(angle))/g; % calculate time to hit

tstep=ceil(T_hit)/100; % calculate t step

tval=[0:tstep:T_hit]; % time steps

for k=1:length(tval)

distance(k,:)=u*cosd(angle)*tval(k); % caluclate horizontal
components

height(k,:)=(u*sind(angle)*tval(k))-0.5*g*tval(k)^2; % calculate
vectical component

plot(distance,height,'ro','MarkerSize',5); % plot the position of
ball

pause(0.01)

xlabel('Distance (in m)');

ylabel('Height (in m)');

ground=0.1.*x;

P=plot(x,ground,'g');

hold on

end

hold off

Thanks for your help, and I will rate positively if help is useful! Thanks!