1. Engineering
  2. Computer Science
  3. i need some help with my matlab code please ...

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

init_velocity=200; %m/s
init_angle=50; %degrees
g=9.8; %accelaeration due to gravity
t=[0:0.01:40]; %time array
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
xlabel('Distance (in m)');
ylabel('Height (in m)');

hold on
hold off

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

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution