hello
try my little demo below
clc
clearvars
nsamples=10;
for k = 1:nsamples
% constants init (my guess / demo)
D = 1;
Mass = 1;
G = 0.1;
V = -1e-3;
Vx = 1e-2+ 1e-2*k;
Vy = 1e-3+ 1e-2*k;
% init recursion arrays
clear t xf x y % mandatory !
t(1) = 0;
n = 1 ;
dt = 1e-2;
x(1) = -1;
xf(1) = 0.5;
y(1) = 0.1;
while min(y)> -0.01
n = n + 1;
t(n) = t(n-1) + dt;
xf(n) = xf(n-1)+ Vx.*dt;
AxD = - ( D / Mass ) * V * Vx;
AyD = -G - ( D / Mass ) * V * Vy;
Vx = Vx + AxD * dt;
Vy = Vy + AyD * dt;
x(n) = x(n-1) + Vx * dt + 0.5 * AxD * dt^2;
y(n) = y(n-1) + Vy * dt + 0.5 * AyD * dt^2;
end
t_end(k) = t(end-1); % sample before "end" to make sure the criteria is met
x_end(k) = x(end-1); % sample before "end" to make sure the criteria is met
y_end(k) = y(end-1); % sample before "end" to make sure the criteria is met
figure(k)
plot(t,y,'-*',t_end(k),y_end(k),'dr')
end
