|
>> g=9.8;
>> l=1;
>> theta=pi/6;
>> x0=l*sin(theta);
>> y0=-l*cos(theta);
>> axis([-.75,0.75,-1.25,0])
>> axis off
>> %用线创建摆捶
>> head = line(x0,y0,'color','r','linestyle','.','erasemode','xor','markersize',40);
>> %用线来创建单摆
>> body = line([0;x0],[0;y0],'color','b','linestyle','-','erasemode','xor');
>> pend
%pend.m文件
t=0;
dt=0.01;
while 1
t=t+dt;
theta0=theta*cos(sqrt(g/l)*t);
x=l*sin(theta0);
y=-l*cos(theta0);
set(head,'xdata',x,'ydata',y);
set(body,'xdata',[0;x],'ydata',[0;y]);
drawnow;
end
给每一位苦战的朋友一份快乐![em09] |
|