function [ Error ] = Shoot( Angle, Speed, Target ) Angle = Angle * pi/180; P = 0 + j*0; v = Speed*( cos(Angle) + j*sin(Angle) ); dt = 0.01; N = 0; plot([-1,100],[-1,50],'w.'); hold on; plot([-1,100],[0,0],'b-'); 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) % clf plot(real(P),imag(P),'r.'); pause(0.1); end end % Use Newton's method to determine where you hit based % upon the last two points % (interpolate to find the zero crossing) x1 = real(zP); y1 = imag(zP); x2 = real(P); y2 = imag(P); x0 = x2 - (x2 - x1)/(y2-y1) * y2; Error = Target - x0; end