欢迎来到天天文库
浏览记录
ID:56912449
大小:11.50 KB
页数:1页
时间:2020-07-23
《单摆的模拟的matlab程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、单摆Matlab代码%绘制横梁plot([-0.2;0.2],[0;0],'-k','LineWidth',20);%画初始位置的单摆g=0.98;%重力加速度,可以调节摆的摆速l=1;%摆长theta0=pi/4;%初始角度x0=l*sin(theta0);%初始x坐标y0=-l*cos(theta0);%初始y坐标axis([-0.75,0.75,-1.25,0]);axisoff%创建摆锤%擦除模式为xorhead=line(x0,y0,'color','r','linestyle','.','erasemode','xor','markersize',40);%创建摆杆
2、body=line([0;x0],[-0.05;y0],'color','b','linestyle','-','erasemode','xor');%摆的运动t=0;%时间变量t1=0.01;%时间增量while1t=t+t1;theta=theta0*cos(sqrt(g/l)*t);%单摆角度与时间的关系x=l*sin(theta);y=-l*cos(theta);if~ishandle(h),return,endset(head,'xdata',x,'ydata',y);%改变擦除对象的坐标数据set(body,'xdata',[0;x],'ydata',[-0.05;
3、y]);drawnow;%刷新屏幕pause(0.1)end
此文档下载收益归作者所有