Question
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
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!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started