why is my plot only showing 1 diagonal line
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
clear
close all
t=0;
V = 0;
dt = 0.1;
S = 3;
CD = 0.1;
T = 10000;
m = 500;
plot(t,V)
hold on
while t<=5
t(end+1)=t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V)
end
while t <=10
t(end+1) = t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V)
end
xlabel('Time (s)')
ylabel('Speed (m/s)')
title('Plot of speed against time')
0 comentarios
Respuestas (2)
Scott MacKenzie
el 10 de Mzo. de 2022
Editada: Scott MacKenzie
el 10 de Mzo. de 2022
First, you probably should move the plot functions outside the while loop. Build up the vectors, then plot!
But, the reason you are seeing only one line is that the two plots are plotting the same line. Below, I demonstrate this by changing the line specs (and moving the plot function outside the loop). You can see the first line plotted in red and the 2nd line plotted on top using a thick black dashed line.
t=0;
V = 0;
dt = 0.1;
S = 3;
CD = 0.1;
T = 10000;
m = 500;
plot(t,V)
hold on
while t<=5
t(end+1)=t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
end
plot(t,V, '-r')
while t <=10
t(end+1) = t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
end
plot(t,V, '--k', 'LineWidth', 5)
xlabel('Time (s)')
ylabel('Speed (m/s)')
title('Plot of speed against time')
0 comentarios
VBBV
el 10 de Mzo. de 2022
clear
close all
t=0;
V = 0;
dt = 0.1;
S = 3;
CD = 0.1;
T = 10000;
m = 500;
% plot(t,V)
hold all
while t<=10
if t<=5
t(end+1)=t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V,'-b')
% hold on
else
t(end+1) = t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V,'-r')
% hold on
end
t = t +1;
end
xlabel('Time (s)')
ylabel('Speed (m/s)')
title('Plot of speed against time')
0 comentarios
Ver también
Categorías
Más información sobre Fluid Dynamics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!