Effacer les filtres
Effacer les filtres

Plotting two variables from a loop

2 vues (au cours des 30 derniers jours)
vauntedmango
vauntedmango le 3 Avr 2020
Commenté : vauntedmango le 3 Avr 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

Réponse acceptée

KSSV
KSSV le 3 Avr 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)
  1 commentaire
vauntedmango
vauntedmango le 3 Avr 2020
Thank you so much! Works

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by