Borrar filtros
Borrar filtros

Plotting two variables from a loop

2 visualizaciones (últimos 30 días)
vauntedmango
vauntedmango el 3 de Abr. de 2020
Comentada: vauntedmango el 3 de Abr. de 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

Respuesta aceptada

KSSV
KSSV el 3 de Abr. de 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)

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by