lunes, 10 de marzo de 2014

Caída libre con rebotes

function rebote(elasticidad,yo)

v = 0;
dt = 1/10;
tf = 50;
g=-9.81;

times = 0:dt:tf;
x=0*times;
z=0*times;
y = zeros(size(times))

for idx = 1:length(times)
newy = yo + (v+g*dt/2)*dt;
v = v + g*dt;
if newy < 0
newy = 0;
v = -v*elasticidad;
end
y(idx) = newy;
yo = newy;
end

for i=1:length(times)
pause(1/100)  
plot3(x(i),z(i),y(i),'o r','MarkerFaceColor','m')
grid on
axis([-2 2 -2 2 min(y) max(y)])
end

end

lunes, 3 de marzo de 2014

Caida fricción sobre resorte amortiguado

 function total2

clc
 
% solucion caida libre
 
 
time1=0:1/10:5;
condini=[100 0];
x=0*time1;
z=0*time1;
  %Resuelvo las ecuaciones diff
[t,y]=ode45(@cfr,time1,condini);
 %solucion masa resorte
  time2=5:1/10:35;
alturafinal=y(length(y(:,1)),1);
velocidadfinal=y(length(y(:,2)),2);
condicionesiniciales=[alturafinal velocidadfinal];
x2=0*time2;
z2=0*time2;
  % desarrolla las ecuaciones diff rk 4 orden
[t2,y2]=ode45(@fk,time2,condicionesiniciales);
 % Unir programa a simular
  tt=[time1 time2];
yt=[y;y2];
xt=[x x2];
zt=[z z2]
 % graficar resultado
  for i=1:length(tt)
pause(1/100)
subplot(2,2,1)
plot(tt,yt(:,2))
subplot(2,2,2)
plot(tt,yt(:,1))
subplot(2,2,3)
plot3(xt(i),zt(i),yt(i,1),'o r','MarkerFaceColor','m')
grid on
axis([-2 2 -2 2 min(yt(:,1)) max(yt(:,1))])
 end
end
  function rk=cfr(t,y)
% Ecuaciones diferenciales caida libre
 
 
m=2;
b=0.01;
g=-9.81;
rk=[y(2);g-(b/m)*y(2)];
 
end
  function rk=fk(t,y)
m=2;
k=10;
c=1;
g=9.81;
rk=[y(2);g-(k/m)*y(1)-(c/m)*y(2)];
 
end



 

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