MATLAB code for damped free vibration closed form solution
m =1; %given data from a problem
k =5;
z =0.05;
x0 =0; %initial conditions
xdot0 =1;
wn =sqrt(k/m); %natural frequency
wd =wn*sqrt(1-z^2) %damped frequency
X1 =x0;
X2 =(xdot0+(z*wn*x0))/wd;
i =1;
alpha =atan(X2/X1); %phase angle
X =sqrt(X1^2+X2^2); %amplitude
for t =0:0.02:15
x(i) =exp(-z*wn*t)*X*cos((wd*t)-alpha);
i =i+1;
end
t =0:0.02:15;
plot(t,x);
grid on;
MATLAB code for damped free vibration numerical solution
m =1; %given data from a problem
k =5;
c=0.223;
wn=sqrt(k/m); %natural frequency
z=c/(2*wn*m); %damping ratio
tol=1e-6; %tolerance value for numerical integration
x0=0; %intitial conditions
xdot0=1;
t=0:0.02:30;
tf=[0 30]; %span for integration
X_IC=[x0 xdot0]; %intitial condition array
[t,y]=ode45(@num_sol,tf,X_IC,tol) %ode solver
x=y(:,1); %displacement
plot(t,x);
grid on;
hold on;
Snippet for function definition
function ydot =num_sol(t,y) %function declaration
m=1; %data from problem
k=5;
c=0.223;
ydot1=y(2); %first order equations
ydot2=-(k*y(1)+c*y(2))/m;
ydot =[ydot1;ydot2]; %2 first orders as array
MATLAB code for undamped free vibration closed form solution
m =1; %data from problem
k =5;
x0=0; %intial conditions
xdot0=1;
wn=sqrt(k/m); %natural frequency
X1=x0;
X2=xdot0/wn;
i=1;
alpha=atan(X2/X1); %phase angle
X=sqrt(X1^2+X2^2); %amplitude
for t=0:0.02:30
x(i)=X*cos((wn*t)-alpha);
i=i+1;
end
t=0:0.02:30;
plot(t,x);
hold on;
MATLAB code for undamped free vibration numerical solution
m =1; %given data from a problem
k =5;
wn=sqrt(k/m); %natural frequency
tol=1e-6; %tolerance value for numerical integration
x0=0; %intitial conditions
xdot0=1;
t=0:0.02:30;
tf=[0 30]; %span for integration
X_IC=[x0 xdot0]; %intitial condition array
[t,y]=ode45(@num_sol,tf,X_IC,tol) %ode solver
x=y(:,1); %displacement
plot(t,x);
grid on;
hold on;
Snippet for function definition
function ydot =num_sol(t,y) %function declaration
m=1; %data from problem
k=5;
ydot1=y(2); %first order equations
ydot2=-k*y(1)/m;
ydot =[ydot1;ydot2]; %2 first orders as array