Plotting two variables from a loop

조회 수: 1 (최근 30일)
Yash Bakrania
Yash Bakrania 2020년 4월 3일
댓글: Yash Bakrania 2020년 4월 3일
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

채택된 답변

KSSV
KSSV 2020년 4월 3일
% 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by