Why won't Matlab plot anything?
1 次查看(过去 30 天)
显示 更早的评论
clear all
close all
% given values %
m = 80; %kg the mass of the sprinter%
F_x= 400; %N%
L = 100; %m the lenght of the race%
p = 1.293; %kg/m^3 the density of the air%
A = 0.45; %m^2 the cross-sectional area%
Cd = 1.2; %the drag force%
w = 0; %air velocity
time = 10;
dt = 0.1;
n = round(time/dt);
D = zeros(n,1);
a = zeros(n,1);
v = zeros(n,1);
x = zeros(n,1);
t = zeros(n,1);
a(1)= F_x/m;
v(1)=0;
x(1)=0;
D(1)=0;
t(1)=0;
for i = 1:n-1
a(i+1) = (F_x - D(i))/m;
v(i+1) = v(i) + a(i)*dt;
D(i+1) = 0.5*p*Cd*A*(v(i)-w)^2;
x(i+1) = x(i)+ v(i)*dt + 0.5*a(i)*dt^2;
t(i+1) = t(i) + dt;
if x(i+1)>=100
return
end
end
f1 = plot(t,x);
f2 = plot(t,v);
f3 = plot(t,a);
This is my code.
plot dose not show up. I hope to get help fixing it
0 个评论
采纳的回答
Dyuman Joshi
2022-9-25
Use break instead of return. As when you use return, any code after it won't be executed
"Be careful when you use return within conditional blocks, such as if or switch, or within loop control statements, such as for or while. When MATLAB reaches a return statement, it does not just exit the loop; it exits the script or function and returns control to the invoking program or command prompt."
m = 80; %kg the mass of the sprinter%
F_x= 400; %N%
L = 100; %m the lenght of the race%
p = 1.293; %kg/m^3 the density of the air%
A = 0.45; %m^2 the cross-sectional area%
Cd = 1.2; %the drag force%
w = 0; %air velocity
time = 10;
dt = 0.1;
n = round(time/dt);
D = zeros(n,1);
a = zeros(n,1);
v = zeros(n,1);
x = zeros(n,1);
t = zeros(n,1);
a(1)= F_x/m;
v(1)=0;
x(1)=0;
D(1)=0;
t(1)=0;
for i = 1:n-1
a(i+1) = (F_x - D(i))/m;
v(i+1) = v(i) + a(i)*dt;
D(i+1) = 0.5*p*Cd*A*(v(i)-w)^2;
x(i+1) = x(i)+ v(i)*dt + 0.5*a(i)*dt^2;
t(i+1) = t(i) + dt;
if x(i+1)>=100
break
end
end
f1 = plot(t,x);
f2 = plot(t,v);
f3 = plot(t,a);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!