function [xt,vt,at] = SDOF_VL(t,wn,xo,vo)
% Resolucion de la ecuacion para vibracion libre sin amortiguamiento
%   Los datos requeridos son: [xt,vt,at] = SDOF_VL(t,wn,xo,vo)
%   [t] → intervalo de tiempo
%   wn → frecuencia natural del sistema
%   xo → desplazamiento inicial
%   vo → velocidad inicial

xt = (xo)*(cos(wn*t))+(vo/wn)*(sin(wn*t));
vt = (-wn*xo)*(sin(wn*t))+(vo)*(cos(wn*t));
at = (wn^2*xo)*(cos(wn*t))-(vo*wn)*(sin(wn*t));
end
function [xt] = SDOF_VLA(t,wn,xo,vo,epsilon)
% Resolucion de la ecuacion para vibracion libre con amortiguamiento
%   Los datos requeridos son: [xt,vt,at] = SDOF_VL(t,wn,xo,vo,epsilon)
%   [t] → intervalo de tiempo
%   wn → frecuencia natural del sistema
%   xo → desplazamiento inicial
%   vo → velocidad inicial
%   epsilon → ratio de amortiguamiento
wd=wn*(1-epsilon^2)^0.5;
a = (exp(-epsilon*wn*t));
b = (xo*cos(wd*t)+((vo+xo*epsilon*wn)/wd)*sin(wd*t));
xt=a.*b;
% Ejercicio de SDOF en vibracion libre con amortiguamiento
% Funcion [xt,vt,at] = SDOF_VLA(t,wn,xo,vo,epsilon)

clear all
clc

% Definimos un intervalo de tiempo discretizado
t=[0:0.05:40];

% Aplicamos la funcion de vibracion libre sin amortiguamienot
wn = 1; %[rad/seg]
xo = 5; %[cm]
vo = 3; %[cm/seg]
epsilon = 0.05;

[x]=SDOF_VLA(t,wn,xo,vo,epsilon);

v=diff(x);
v=[v v(end)];    % Se añade un valor al vector para tener la misma dimension

a=diff(v);
a=[a a(end)];    % Se añade un valor al vector para tener la misma dimension

% Decremento
rho=(xo^2)

subplot (3,1,1)
plot (t,x)
title('x(t)')

subplot (3,1,2)
plot (t,v)
title('v(t)')

subplot (3,1,3)
plot (t,a)
title('a(t)')