⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pend.m

📁 matlab下的离散系统仿真模型和相关事例,具有很好的参考价值
💻 M
字号:
figure('color',[1 1 1])
plot([-0.2;0.2],[0;0],'color','y','linestyle','-','linewidth',10);%画悬线的横梁
g=9.8;                                                            %重力加速度
l=1;                                                              %线长
theta0=pi/6;                                                      %初始角度
x0=l*sin(theta0);                                                 %初始 x 值
y0=-l*cos(theta0);                                                %初始 y 值
axis([-0.75,0.75,-1.25,0]);                                       %画坐标范围
axis('off');                                                      %关闭坐标显示
head=line(x0,y0,'color','r','linestyle','.','erasemode','xor','markersize',40);    %定义小球格式
%mmonth=line(x0,y0,'color','g','linestyle','.','erasemode','xor','markersize',30);
body=line([0;x0],[0;y0],'color','b','linestyle','-','erasemode','xor');            %定义悬线格式
t=0;                                                              %时间初值
dt=0.005;                                                          %时间增量
while 1                                                           %死循环(关闭窗口后中止循环)
   t=t+dt;
   theta=theta0*cos(sqrt(g/l)*t);                                 %计算时刻 t 时的幅角                               
   x=l*sin(theta);                                                %计算时刻 t 时的 x 坐标
   y=-l*cos(theta);                                               %计算时刻 t 时的 y 坐标
   set(head,'xdata',x,'ydata',y);                                 %计算时刻 t 时小球的位置
   set(body,'xdata',[0;x],'ydata',[0;y]);                         %计算时刻 t 时悬线的位置
   drawnow;                                                       %重画小球与悬线
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -