为方便大家复制代码,我重新整理一下程序!- clear all;
- clear;
- clc;
- rectangle('position',[12,1.2,2,0.2],'FaceColor',[0.5,0.3,0.4]);
- axis([0,15,-5,15]);
- %画顶板
- hold on
- %画直线
- y=1.5:.35:5.5;
- M=length(y);
- x=12+mod(1:M,2)*2;
- x(1)=13;
- x(end-3:end)=13;
- D=plot(x,y);
- %弹簧 D
- C=(1/8:1/4:7/8)*2*pi;r=0.35;
- t1=2*r*sin(C);
- F1=fill(13+3*r*cos(C),5.5+t1,'r');
- % 球
- % set(gca,'ytick',[0:2:9]);
- % set(gca,'yticklabels',num2str([-1:3]'));
- plot([0,15],[5.9,5.9],'black');
- H1=plot([0,13],[5.9,5.9],'y');
- % 句柄[黄线]
- Q=plot(0,5.5,'color','r');
- % 运动曲线;
- td=[];yd=[];
- text(2,14,'阻尼振动','fontsize',16);
- set(gcf,'doublebuffer','on');
- %有阻尼自由衰减振动分析计算程序
- k=80; %N/m
- m=10; %Kg
- c=0.219*sqrt(k*m)*2;%N.s/m
- x0=-2;
- v0=-10;
- X1=[x0,v0]';
- p=sqrt(k/m);
- n=c/(2*m);
- f=p/(2*pi);
- ksai=n/p;
- T0=1/f;
- T1=T0*(1/sqrt(1-ksai^2));
- T1_T=T1/T0;
- A2_A1=1/exp(n*T1);
- s1=-n+sqrt(n^2-p^2);
- s2=-n-sqrt(n^2-p^2);
- s=[1,1;s1,s2];
- Cd=inv(s)*X1;
- T=0;
- while T<12;
- pause(0.2);
- Dy=real(Cd(1)*exp(s1*T)+Cd(2)*exp(s2*T))/4+1.15;
- Y=(y-1.5)*Dy+1.5;
- Yf=Y(end)+t1;
- td=[td,T];yd=[yd,Y(end)];
- set(D,'ydata',Y);
- set(F1,'ydata',Yf,'facecolor',rand(1,3));
- set(H1,'xdata',[T,13],'ydata',[Y(end),Y(end)]);
- set(Q,'xdata',td,'ydata',yd) ;
- T=T+0.1;
- end
复制代码 补充一个多自由度的振动程序(参考张亚辉结构动力学基础)
- function newmark(t_max,dt)
- %t_max为持续时间,dt为时间步长
- M=1*[1 0 0;0 1 0;0 0 1];
- K=1*[3 -1 0;-1 2 -1;0 -1 1];
- C=0.015*M+0.02*K;%c=0.015*[0 0 0;0 0 0;0 0 0];
- u=[0 0 0]';
- v=[0 0 0]';
- a=[0 0 0]';
- t(1)=0; %时间
- x(:,1)=u; %位移
- x1(:,1)=v; %速度
- x2(:,1)=a; %加速度
- %newmark参数
- gama=0.5;
- delta=0.25;
- a0=1/(delta*dt^2);
- a1=gama/(delta*dt);
- a2=1/(delta*dt);
- a3=1/(2*delta)-1;
- a4=gama/delta-1;
- a5=dt*(gama/(2*delta)-1);
- a6=dt*(1-gama);
- a7=gama*dt;
- %等效刚度矩阵
- K1=K+a0*M+a1*C;
- i=1;
- t(1)=0;
- while t(i)<t_max
- Q=-1*[sin(t(i)) sin(t(i)) sin(t(i))]';
- q(:,i+1)=Q+M*(a0*x(:,i)+a2*x1(:,i)+a3*x2(:,i))+C*(a1*x(:,i)+a4*x1(:,i)+a5*x2(:,i));
- x(:,i+1)=inv(K1)*q(:,i+1);
- x2(:,i+1)=a0*(x(:,i+1)-x(:,i))-a2*x1(:,i)-a3*x2(:,i);
- x1(:,i+1)=a1*(x(:,i+1)-x(:,i))-a4*x1(:,i)-a5*x2(:,i);
- i=i+1;
- t(i)=t(i-1)+dt;
- end
- x1=x(1,:)';
- x2=x(2,:)';
- x3=x(3,:)';
- xx1=x1(1:t_max/dt)';
- xx2=x2(1:t_max/dt)';
- xx3=x3(1:t_max/dt)';
- t=dt:dt:t_max;
- plot(t,xx1,'-',t,xx2,'-.',t,xx3,'--')
- xlabel('t[sec]')
- ylabel('x(m)')
- legend('x1(t)','x2(t)','x3(t)')
- grid
复制代码 在Matlab命令窗口输入:输入:newmark(30,0.01)
另外,大家还可以参考一下这个帖子:http://forum.vibunion.com/thread-30794-1-1.html(关于多自由度 自由振动 MATLAB 仿真 的,里面有程序,又仿真结果,很详细!!)
|