clear;clc;close all
l=4;
m=1;
g=9.81;
zeta=0.2;
I=m*l^2;
w0=sqrt(g/l);
c=zeta*2*w0*I;
dt=0.2/w0;
theta(1)=0.6;
dtheta(1)=0;
Ek=0.5*m*(l*dtheta(1))^2;
Ep=l*(1-cos(theta(1)))*m*g;
figure
h1=subplot(2,1,1);
set(h1,'XLim',[-8 8],'YLim',[-5 0])
set(gca,'drawmode','fast')
line_handle1=plot([0 l*sin(theta(1))],[0 -l*cos(theta(1))],'-o');
axis equal
title('Pendulum Simulation')
blank=[' '];
parameters={['Length' blank(1:14) num2str(l)];['Mass' blank(1:16) num2str(m)]; ...
['Damping ratio' blank(1:4) num2str(zeta)];['Gravity' blank(1:14) num2str(g)]};
text(3,-1.5,parameters)
text_show={['Time' blank(1:10) '0'];['Theta' blank(1:9) num2str(theta(1))]; ...
['dTheta/dt' blank(1:4) num2str(dtheta(1))];['Energy' blank(1:7) num2str(Ek+Ep)]};
text_handle=text(-7.5,-3.5,text_show);
h2=subplot(2,1,2);
set(h2,'XLim',[-0.8 0.8],'YLim',[-0.8 0.8])
set(gca,'drawmode','fast')
line_handle2=plot(theta(1),dtheta(1));
axis equal
title('theta-dtheta curve')
xlabel('theta (rad)')
ylabel('dtheta (rad/s)')
N=80;
for k=1:N
Tw=5*sin(2*(k-1)*dt);
ddtheta(k)=(Tw/I)-(g/l)*sin(theta(k))-(c/(m*l^2))*dtheta(k);
dtheta(k+1)=dtheta(k)+dt*ddtheta(k);
theta(k+1)=theta(k)+dt*dtheta(k);
Ek=0.5*m*(l*dtheta(k+1))^2;
Ep=l*(1-cos(theta(k+1)))*m*g;
set(line_handle1,'xdata',[0 l*sin(theta(k+1))],'ydata',[0 -l*cos(theta(k+1))])
set(h1,'XLim',[-8 8],'YLim',[-5 0])
text_show={['Time' blank(1:10) num2str(k*dt)];['Theta' blank(1:9) num2str(theta(k+1))]; ...
['dTheta/dt' blank(1:4) num2str(dtheta(k+1))];['Energy' blank(1:7) num2str(Ek+Ep)]};
set(text_handle,'string',text_show)
set(line_handle2,'xdata',theta,'ydata',dtheta)
set(h2,'XLim',[-0.8 0.8],'YLim',[-0.8 0.8])
drawnow
pause(0.001)
end
msgbox('MATLAB编程答疑,请加QQ: 1530497909','MATLAB答疑','help')
web http://url.cn/NSFcAs -browser
阿里matlab建模师
- 粉丝: 4386
- 资源: 2852
最新资源
- 7.(备用)180题自动计算结果(6不能用则用7).xls
- 机械设计饲料搅拌机sw18全套设计资料100%好用.zip
- DISC测试题目(详细版).doc
- DISC评分表格.xls
- Java项目:校园周边美食探索(java+SpringBoot+Mybaits+Vue+elementui+mysql)
- 明达集团招聘管理制度-终.doc
- 招聘与录用管理制度.doc
- 标准HR面试话术.doc
- 经理面试话术.doc
- 大学远程教育-计算机网络试卷题目.docx
- 技术人员面试话术.doc
- 电话邀约销售面试话术.doc
- hr电话邀约面试考察话术.doc
- 面试预约话术.doc
- python入门5个经典案例含代码示例.docx
- 基于FPGA实验板的多功能数字时钟-利用Quartus实现设计与仿真源码+课程设计报告
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈