why is my plot only showing 1 diagonal line
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Scott MacKenzie
am 10 Mär. 2022
Bearbeitet: Scott MacKenzie
am 10 Mär. 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 Kommentare
VBBV
am 10 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Fluid Dynamics 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!