function [ Error ] = Shoot( Speed, Angle, Target ) Angle = Angle * pi/180; % Speed = 30; % Target = 90 + j*0; P = 0 + j*0; v = Speed*( cos(Angle) + j*sin(Angle) ); dt = 0.01; N = 0; plot([-1,100],[0,0],'b-'); hold on plot(real(Target), imag(Target), 'bx'); zP = 0; while(imag(P) >= 0) N = mod(N+1, 10); zP = P; wind = -( abs(v)^2 ) * v * 1e-4; a = wind - j*9.8; v = v + a*dt; P = P + v*dt; if(N == 0) plot(real(P),imag(P),'r.'); xlim([0,130]); ylim([0,100]); pause(0.1); end end x1 = real(zP); y1 = imag(zP); x2 = real(P); y2 = imag(P); x0 = x2 - (x2 - x1)/(y2-y1) * y2; Error = Target - x0; end