Why won't Matlab plot anything?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Akram Khandash
el 25 de Sept. de 2022
Comentada: Akram Khandash
el 26 de Sept. de 2022
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 comentarios
Respuesta aceptada
Dyuman Joshi
el 25 de Sept. de 2022
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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Digital Filter Analysis 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!