Sunteți pe pagina 1din 2

%forced Vibrations

clear;clc
%
k=1;m=1;z=0;
wn=sqrt(k/m);
A=[0 1;(-wn^2) (-2*z*wn)];
B=[0;1/m];
C=[1 0];
D=0;
u0=[0;0];
t=0:0.05:50;
%Unit Step
F1=ones(1,length(t));
[y,u]=lsim(A,B,C,D,F1,t,u0);
plot(t,u(:,1),'linewidth',2),xlabel('Time
(sec)'),ylabel('Position (in)'),grid on
title('Unit Step');
pause
%Ramp
p0=50;
tr=25;
t1=0:0.1:tr;
F1=(p0/tr)*t1 ;%line slope p0/tr
[y,u]=lsim(A,B,C,D,F1,t1,u0);
plot(t1,u(:,1),'linewidth',2),xlabel('Time
(sec)'),ylabel('Position (in)'),grid on
title('Ramp');
pause
%Ramp-to-Step
p0=50;
tr=10;
t2=0:0.1:tr;
t3=(tr+0.1):0.1:50;
t4=[t2,t3];%connects the two time vectors
F2=(p0/tr)*t2;%generates line of slope p0/tr
F3=p0*ones(1,length(t3));%generates flat line
F4=[F2,F3];%connects the two functions into one vector
[y,u]=lsim(A,B,C,D,F4,t4,u0);
plot(t4,u(:,1),'linewidth',2),xlabel('Time
(sec)'),ylabel('Position (in)'),grid on
title('Ramp-to-Step')

%This subroutine calculates the response of a one d.o.f


structure
%subjected to harmonic vibration
%
clear;clc;
k=1;m=1;z=0;
wn=sqrt(k/m);%calculating natural frequency
u0=[0;0];%[initial displacement;initial velocity]
A=[0 1;(-wn^2) (-2*z*wn)];
%
T=2*pi/wn;
t=0:0.01:20*T ; %simulation time
%
B=[0;1/m];C=[1 0];D=0;
multiplier=[0.1 0.9 0.99 ];
for i=1:length(multiplier)
multi=multiplier(i);
f=1*sin(multi*wn*t);
[y,u]=lsim(A,B,C,D,f,t,u0);
x(:,i)=u(:,1);%save displacement for plotting
end
a='0.1*natFrequency';
b='0.9*natFrequency';
c='0.99*natFrequency';
plot(t,x,'linewidth',2),xlabel('Time(sec)'),ylabel('Displ
acement
(in)'),grid on
legend(a,b,c)