|
楼主 |
发表于 2010-4-5 22:47
|
显示全部楼层
下面我贴上代码:
% basic known conditions:
m=0.2533;
k=10;
wn=sqrt(k/m);
zeta=0.05;
c=zeta*(2*m*wn);
wd=wn*sqrt( 1-zeta^2 );
dt=0.001;
u0=0;
v0=0;
p0=10;
w=pi/0.6;
T=12;
%----------------------------------------------------------------------------
% the following parameters for solving analytical solutions
CC=p0/k*( 1-(w/wn)^2 )/( (1-(w/wn)^2)^2+(2*zeta*(w/wn))^2 );
DD=p0/k*( -2*zeta*(w/wn))/( (1-(w/wn)^2)^2+(2*zeta*(w/wn))^2 );
AA=u0-DD;
BB=1.0/wd*(v0+zeta*wn*AA-w*CC);
%----------------------------------------------------------------------------
time=0:dt:T;
force=sin(w.*time)*p0;
% analytical solution:
u_analytical=exp(-zeta.*wn.*time).*(AA.*cos( wd.*time)+BB.*sin( wd.*time))+CC.*sin(w.*time)+DD.*cos(w.*time);
% ***********plot ***u(t)*** graph***************
figure
plot(time, u_analytical,'.')
axis tight
xlabel('Time(s)')
title('U(z) history curve by analytical method')
grid on
% ***********************************************
sz=length(time);
% using tfestimate() fuction to solving transfer function Hn_tfe,
Fc=1.0/dt;
window=hanning(sz);
[Tfn_tfe,f]=tfestimate(force,u_analytical,window,sz*0.5,sz,Fc); % f's unit is Hz
% ******************plot ****tranfer function****graph***************
figure
subplot(1,3,1)
plot( f, real(Tfn_tfe),'r.')
title('transfer function--real part')
grid on
xlabel('f(Hz)')
subplot(1,3,2)
plot(f,imag(Tfn_tfe),'b.')
title('transfer function--imag part')
grid on
xlabel('f(Hz)')
subplot(1,3,3)
plot(f,abs(Tfn_tfe),'k.')
title('transfer function--amplitude')
grid on
xlabel('f(Hz)')
% ********************************************************************
omiga=2*pi*(1/dt)*(0:sz/2-1)/sz; % omiga's unit is rad/s
Hn=p0./(-omiga.^2.*m+j.*omiga.*c+k);
% **************plot *** Comparing ****graph**********************
headpos=100;
intval=1;
omiga=omiga/2/pi; % omiga's unit is Hz
figure
subplot(1,3,1)
plot(omiga(headpos:intval:end),real(Hn(headpos:intval:end)),'r',f(headpos:intval:end),real(Tfn_tfe(headpos:intval:end)),'bo')
grid on
xlabel('f(Hz)')
legend('analytical method','numerical method')
title('Comparing two kind of transfer function value--real part')
subplot(1,3,2)
plot(omiga(headpos:intval:end),imag(Hn(headpos:intval:end)),'r',f(headpos:intval:end),imag(Tfn_tfe(headpos:intval:end)),'bo')
grid on
xlabel('f(Hz)')
legend('analytical method','numerical method')
title('Comparing two kind of transfer function value--imag part')
subplot(1,3,3)
plot(omiga(headpos:intval:end),abs(Hn(headpos:intval:end)),'r',f(headpos:intval:end),abs(Tfn_tfe(headpos:intval:end)),'bo')
grid on
xlabel('f(Hz)')
legend('analytical method','numerical method')
title('Comparing two kind of transfer function value--amplitude')
% ******************************************************************** |
|