I am currently doing a school project where i have to plot the trajectory of a projectile launched from the ground with initial speed V0, and angle theta above the horizontal. The projectile has to hit a target distance D=10000m away once it has reached the ground. I have used an initial guess of theta=pi/30 as the angle, so that the projectile does not reach D. The program should then automatically pick a new value of theta. I am doing this by increasing theta from pi/30 in steps dtheta=0.1 until the target is overshot. However, after plotting, I keep getting a wrong and wild graph. Here is my code:
%contants D=10000; u=600; m=50; g=9.81;
%initial conditions theta=pi/30; x=0; i=0; t=0; y=0; dtheta=0.1; dt=0.1;
xdot(i)=u*cos(theta); ydot(i)=u*sin(theta); v(i)=sqrt(xdot(i).^2+ydot(i).^2);
if y(i+1)<0 break end end
if x(i+1)<D theta=theta+dtheta; if x(i+1)>D break end end
plot(x,y),grid xlabel('Distance/[m]') ylabel('Height/[m]')
No products are associated with this question.