Professional Documents
Culture Documents
Matlab code:
The code assumes a sinusoidal base function. Also, the program tests three
different natural frequencies.
y0=input('Enter the base excitation magnitude. ');
zeta=input('Enter the damping ratio (zeta). ');
if (zeta<0 | zeta>=1) % The usual test on damping ratio.
error('Damping ratio not in acceptable range!')
end
wn=4;
tf=10;
t=0:tf/1000:tf;
for k=1:3
wb(k)=input('Enter a base excitation frequency. ');
end
for m=1:3
wd=wn*sqrt(1-zeta^2);
phi1=atan2(2*zeta*wn*wb(m),(wn^2-wb(m)^2));
phi2=atan2(wn,2*zeta*wb(m));
xi=phi1+phi2;
Z1=(-zeta*wn-wb(m)*tan(xi)+sqrt((zeta*wn)^2+2*zeta* ...
wn*wb(m)*tan(xi)+(wb(m)*tan(xi))^2+wd^2))/wd;
Z2=(-zeta*wn-wb(m)*tan(xi)-sqrt((zeta*wn)^2+2*zeta* ...
wn*wb(m)*tan(xi)+(wb(m)*tan(xi))^2+wd^2))/wd;
Anum=sqrt((wn^2+(2*zeta*wb(m))^2)/((wn^2-wb(m)^2)^2+(2* ...
zeta*wb(m)*wn)^2))*wn*y0;
Bnum1=(-wd*cos(xi)+Z1*zeta*wn*cos(xi)+Z1*wb(m)*sin(xi));
Bnum2=(-wd*cos(xi)+Z2*zeta*wn*cos(xi)+Z2*wb(m)*sin(xi));
Aden1=wd*Z1;
Aden2=wd*Z2;
A1=Anum*Bnum1/Aden1;
A2=Anum*Bnum2/Aden2;
th1=2*atan(Z1);
th2=2*atan(Z2);
y1(m,:)=A1*exp(-zeta*wn*t).*sin(wd*t+th1);
y2(m,:)=A2*exp(-zeta*wn*t).*sin(wd*t+th2);
end
%This portion solves the steady-state response.
for j=1:3
A=sqrt((wn^2+(2*zeta*wb(j))^2)/((wn^2-wb(j)^2)^2+(2*zeta* ...
wn*wb(j))^2));
phi1=atan2(2*zeta*wn*wb(j),(wn^2-wb(j)^2));
phi2=atan2(wn,(2*zeta*wb(j)));
xp(j,:)=wn*y0*A*cos(wb(j)*t-phi1-phi2);
end
if (xp(1,1)+y1(1,1)==xp(2,1)+y1(2,1)==xp(3,1)+y1(3,1)==0)
x=xp+y1;
else
x=xp+y2;
end
for i=1:3
subplot(3,1,i)
plot(t,x(i,:))
ylabel('Response x');
title(['Base Excitation with wb=',num2str(wb(i)), ...
'and wn=',num2str(wn)]);
grid
end
xlabel('Time, seconds')
10
0
-10
10
10
10
100
0
-100
Response x
Response x
Response x
Enter
Enter
Enter
Enter
Enter
10
0
-10
4
5
6
Time, seconds
wdr=3;
wn=3.5;
fo=4;
tf=10;
t=0:tf/1000:tf;
for k=1:3
zeta(k)=input('Enter a damping ratio (zeta). ');
if (zeta(k)<0 | zeta(k)>=1)
error('Zeta out of range for this program!')
end
end
for k=1:3
wd=wn*sqrt(1-zeta(k)^2);
Ao=fo/sqrt((wn^2-wdr^2)^2+(2*zeta(k)*wn*wdr)^2);
phi=atan2(2*zeta(k)*wn*wdr,(wn^2-wdr^2));
Z1=-zeta(k)*wn-wdr*tan(phi);
Z2=sqrt((zeta(k)*wn)^2+2*zeta(k)*wn*wdr*tan(phi)+ ... % Continuation.
(wdr*tan(phi))^2+wd^2);
Z=(Z1+Z2)/wd;
Anum=Ao*((zeta(k)*wn*Z-wd)*cos(phi)+wdr*Z*sin(phi));
Aden=Z*wd;
A=Anum/Aden;
theta=2*atan(Z);
x(k,:)=A*exp(-zeta(k)*wn*t).*sin(wd*t+theta)+Ao*cos(wdr*t-phi);
end
for k=1:3
subplot(3,1,k)
plot(t,x(k,:))
title(['Response for zeta=',num2str(zeta(k)),', wn=', ...
num2str(wn),', and wdr=', num2str(wdr)])
ylabel('Response x')
grid
end
xlabel('Time, seconds')
Response x
Response x
Response x
2
0
-2
10
10
10
2
0
-2
1
0
-1
4
5
6
Time, seconds