Azzera filtri
Azzera filtri

Plotting two variables from a loop

2 visualizzazioni (ultimi 30 giorni)
vauntedmango
vauntedmango il 3 Apr 2020
Commentato: vauntedmango il 3 Apr 2020
Hi, the code below indicates 2D equations of the projectile of a payload delivery system. The numerical process induces varying values for 'x' and 'y'. I am trying to plot the projectile motion of the object (so x vs. y) for every time step (loop). How can I do this?
% Constants
g=9.81;
m=1.5;
A=0.028;
Cd=0.8;
rho=1.225;
B=(rho*Cd*A)/2;
Dt=1e-6;
% Initial values
x=0;
y=6.4008; %21 ft
V=12.5;
alpha=90;
Vx=V*sind(alpha);
Vy=V*cosd(alpha);
t=0;
for k=1:1e9
if y<0
break
end
ax= -(B/m)*(V*Vx);
ay=(B/m)*(V*Vy)-g;
x=x+Vx*Dt+0.5*ax*(Dt^2);
y=y+Vy*Dt+0.5*ay*(Dt^2);
Vx=Vx+ax*Dt;
Vy=Vy+ay*Dt;
V=sqrt((Vx^2)+(Vy^2));
t=t+Dt;
end

Risposta accettata

KSSV
KSSV il 3 Apr 2020
% Constants
g=9.81;
m=1.5;
A=0.028;
Cd=0.8;
rho=1.225;
B=(rho*Cd*A)/2;
Dt=1e-6;
% Initial values
x=0;
y=6.4008; %21 ft
V=12.5;
alpha=90;
Vx=V*sind(alpha);
Vy=V*cosd(alpha);
t=0;
X = zeros([],1) ;
Y = zeros([],1) ;
for k=1:1e9
if y<0
break
end
ax= -(B/m)*(V*Vx);
ay=(B/m)*(V*Vy)-g;
x=x+Vx*Dt+0.5*ax*(Dt^2);
y=y+Vy*Dt+0.5*ay*(Dt^2);
Vx=Vx+ax*Dt;
Vy=Vy+ay*Dt;
V=sqrt((Vx^2)+(Vy^2));
t=t+Dt;
X(k) = x ;
Y(k) = y ;
end
plot(X,Y)

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by