lunes, 3 de marzo de 2014

Simulación masa resorte vertical

function resorte_clase

% declara variables

time=0:1/10:30;
condicionesiniciales=[20 0];

x=0*time;
z=0*time;

% desarrolla las ecuaciones diff rk 4 orden
[t,y]=ode45(@fk,time,condicionesiniciales)

y1=-y(:,1)
% graficas

for i=1:length(time)

pause(1/100)
subplot(2,2,1)
plot(time(i),y(i,2),'-')
xlabel('tiempo (s)')
ylabel('velocidad (m/s)')
hold on

subplot(2,2,3)
plot(time(i),y1(i))
xlabel('tiempo (s)')
ylabel('posición (m)')
hold on

subplot(2,2,2)
plot(y(i,2),y1(i))
ylabel('posición (m)')
xlabel('velocidad (m/s)')
hold on

subplot(2,2,4)
plot3(x(i),z(i),y1(i),'o r','MarkerFaceColor','m')
axis([-2 2 -2 2 min(y1)-2 max(y1)+2])
grid on
ylabel('posición (m)')
xlabel('posición (m)')
zlabel('posición (m)')



end

end

function rk=fk(t,y)
m=2;
k=2;
b=0.5;
g=9.81;
rk=[y(2);g-(k/m)*y(1)-(b/m)*y(2)];
end

1 comentario: