How to create a plot with this code?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
BRS
am 19 Dez. 2017
Beantwortet: Star Strider
am 19 Dez. 2017
When trying to plot a graph nothing but the x axis and y axis are displayed in the figure. The code is for drawing the approximate path of a projectile which is experiencing drag.
close all
%constants and starting conditions
g =-9.81;
A = 0.25 * pi * (0.01512); %with 15.12mm the diameter of the projectile
ro = 1.293; %Binas' air density at 20C at sea level
c = 0.47; %drag coefficient for a sphere
B = 45; %launch angle
Xx = 0;
Xy = 1-sin(B)*0.202; %projectile-floor height in meters
Vc = 10.66; %launch speed in meters per second
Vx = sin(B)*Vc; %horizontal speed vector
Vy = cos(B)*Vc; %vertical speed vector
dt = 0.1; %timestep
m = 0.001684;%projectile mass in kilograms
awx(1) = 0;
awy(1) = 0;
dVy(1) = 0;
dVx(1) = 0;
dXx(1) = 0;
dXy(1) = 0;
Fwx(1) = 0;
Fwy(1) = 0;
t(1) = 0;
%model
while Xy >= 0
ax = awx;
Vx = Vx+dVx;
dVx = ax*dt;
Xx = Xx+dXx;
dXx = Vx*dt+0.5*ax*(dt)^2;
ay = g+awy;
Vy = Vy+dVy;
dVy = ay*dt;
Xy = Xy+dXy;
dXy = Vy*dt+0.5*ay*(dt)^2;
Vd = sqrt((Vx)^2+(Vy)^2);%sum of both speed vectors in flight
Fw = -0.5*ro*A*c*(Vd)^2;
theta = atan((Vx)/(Vy));%angle of Vd in fight
Fwy = cos(theta)*Fw;
Fwx = sin(theta)*Fw;
awx = (Fwx)/m;
awy = (Fwy)/m;
t = t+dt;
end
plot(Xx,Xy)
xlabel('x (m)')
ylabel('y (m)')
title('Projectile Path')
0 Kommentare
Akzeptierte Antwort
Star Strider
am 19 Dez. 2017
You need to subscript and save ‘Xx’ and ‘Xy’, I created ‘Xxv’ and ‘Xyv’ to do this, and also ‘tv’ to save the time vector if you need it.
This plots:
%model
k = 1;
while Xy >= 0
ax = awx;
Vx = Vx+dVx;
dVx = ax*dt;
Xx = Xx+dXx;
dXx = Vx*dt+0.5*ax*(dt)^2;
Xxv(k) = Xx;
ay = g+awy;
Vy = Vy+dVy;
dVy = ay*dt;
Xy = Xy+dXy;
dXy = Vy*dt+0.5*ay*(dt)^2;
Xyv(k) = Xy;
Vd = sqrt((Vx)^2+(Vy)^2);%sum of both speed vectors in flight
Fw = -0.5*ro*A*c*(Vd)^2;
theta = atan((Vx)/(Vy));%angle of Vd in fight
Fwy = cos(theta)*Fw;
Fwx = sin(theta)*Fw;
awx = (Fwx)/m;
awy = (Fwy)/m;
t = t+dt;
tv(k) = t;
k = k + 1;
end
plot(Xxv,Xyv)
xlabel('x (m)')
ylabel('y (m)')
title('Projectile Path')
You likely still have some work to do on this.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Vector Fields finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!