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实现单摆在外力矩作用下的动画 源程序代码.zip
版权申诉
100 浏览量
2022-04-01
16:13:26
上传
评论
收藏 2KB ZIP 举报
![avatar](https://profile-avatar.csdnimg.cn/2588731bac124b388c4a87fce0b1493c_m0_53407570.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
阿里matlab建模师
- 粉丝: 3400
- 资源: 2788
最新资源
- Screenshot_20240703_230017_com.tencent.mm.jpg
- com.shouzhi.pndr2-1_sign.apk
- python-leetcode python题解之第654题最大二叉树
- WebBrowser控件的常用方法、属性和事件
- python-leetcode python题解之第628题三个数的最大乘积
- python-leetcode python题解之第617题合并二叉树
- python-leetcode python题解之第605题种花问题
- python-leetcode python题解之第581题最短无序连续子数组
- python-leetcode python题解之第572题另一棵树的子树
- python-leetcode python题解之第560题和为K的子数组
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)