Plotting the values from a for loop - can someone help me plot t against v?
Mostrar comentarios más antiguos
X0 = 0; %Initial displacements of blocks
x = X0;
V0 = 0; %Initial velocities of blocks
v = V0;
vp = 0.0001;
o = 0.01;
alpha = 2;
F = (1-o)/(1+2*alpha*abs(v)/(1-o));
t=0;
delta_t=0.01;
x=[];
for t=0:1:200 % time step given between two colons
a = vp.*0.01-x-F;
v = (a.*0.01) +v;
F = (1-o)./(1+2.*alpha.*abs(v)./(1-o));
x = (v.*0.01) +x;
end
t=0:200;
plot(t,x)
Respuestas (2)
KSSV
el 8 de Mzo. de 2017
X0 = 0; %Initial displacements of blocks
x = X0;
V0 = 0; %Initial velocities of blocks
v = V0;
vp = 0.0001;
o = 0.01;
alpha = 2;
F = (1-o)/(1+2*alpha*abs(v)/(1-o));
delta_t=0.01;
t = 0:1:200 ;
x = zeros(size(t)) ;
x(1) = 0 ;
for i=2:length(t) % time step given between two colons
a = vp.*0.01-x(i)-F;
v = (a.*0.01) +v;
F = (1-o)./(1+2.*alpha.*abs(v)./(1-o));
x(i) = (v.*0.01) +x(i-1);
end
plot(t,x)
Check the equations once.
Jan
el 8 de Mzo. de 2017
delta_t = 0.01;
t = (0 : 200) * delta_t
x = zeros(1, numel(t));
v = zeros(1, numel(t));
a = zeros(1, numel(t));
F = zeros(1, numel(t));
x(1) = x0;
v(1) = v0;
for ti = 2:numel(t)
F(ti) = (1-o)./(1+2.*alpha.*abs(v)./(1-o));
a(ti) = vp * delta_t - x(ti-1) - F(ti);
v(ti) = a(ti) * delta_t) + v(ti-1);
x(ti) = v(ti) * delta_t) + x(ti-1);
end
plot(t, x);
Categorías
Más información sobre General Applications en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!