绳拉线轴的运动 物理系 2001 级程鹏学号 01261094 如图所示, 一绳拉动线轴在水平面上做无滑滚动 线轴与地面的接触点为瞬心 根据在惯性系中刚体对瞬心的角动量定理得, 当绳与地面的夹角大于角 A 时, 力 F 对瞬心的力矩使线轴逆时针转动, 反之当绳与地面的夹角小于角 A 时, 线轴顺时针转动 源程序如下 : %%program gz.m f=1; R=5;r=2; m=10;l=8; theta=pi/6; [t,u]=ode45( gzfun,[0:0.001:5],[0,0],[],f,r,r,m,theta); x=r*u(:,1);y=r*ones(length(t),1); ll=l*ones(length(t),1);rr=r*ones(length(t),1); xa=x+rr*sin(theta);ya=y-rr*cos(theta); xb=xa+(ll+r*u(:,1))*cos(theta); yb=ya+(ll+r*u(:,1))*sin(theta); xc=x-r*sin(u(:,1));yc=y-r*cos(u(:,1)); xd=x-r*sin(u(:,1));yd=y-r*cos(u(:,1)); figure axis([-20,20,-2,5]); axis equal hold on a10=line([-20,20],[0,0], color, k, linewidth,3.5); a20=linspace(-20,20,80); for i=1:79 a30=(a20(i)+a20(i+1))/2; plot([a20(i),a30],[0,0-0.5], color, b,... linestyle, -, linewidth,1); fai=0:0.01:7;fai1=rot90(fai);yy=r*ones(length(fai),1); px=r*cos(fai1);py=yy+r*sin(fai1); qx=r*cos(fai1);qy=yy+r*sin(fai1); ball1=line(px,py, color, b, linewidth,2, erasemode, xor ); ball2=line(qx,qy, color, b, linewidth,2, erasemode, xor );
xian=line([xa(1),xb(1)],[ya(1),yb(1)], color, k,... gan=line([xc(1),xd(1)],[yc(1),yd(1)], color, k,... for i=1:length(t) xx=x(i)*ones(length(fai),1); pxx=xx+r*cos(fai1);pyy=yy+r*sin(fai1); qxx=xx+r*cos(fai1);qyy=yy+r*sin(fai1); set(ball1, xdata,pxx, ydata,pyy); set(ball2, xdata,qxx, ydata,qyy); set(xian, xdata,[xa(i),xb(i)], ydata,... [ya(i),yb(i)]); set(gan, xdata,[xc(i),xd(i)], ydata,... [yc(i),yd(i)]); drawnow function udot=gzfun(t,u,flag,f,r,r,m,theta) udot=[u(2); 2*f*(R*cos(theta)-r)/3*m*(R^2)]; function varargout = jiemian(varargin) % JIEMIAN Application M-file for jiemian.fig % FIG = JIEMIAN launch jiemian GUI. % JIEMIAN( callback_name,...) invoke the named callback. % Last Modified by GUIDE v2.0 24-Jun-2003 12:46:59 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename, reuse ); % Generate a structure of handles to pass to callbacks, and store it. Handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try if (nargout) else [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); ABOUT CALLBACKS: GUIDE automatically apps subfunction prototypes to this file, and sets objects callback properties to call them through the FEVAL switchyard above. This comment describes that mechanism. Each callback subfunction declaration has the following form: <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) The subfunction name is composed using the object s Tag and the callback type separated by _, e.g. slider2_callback, figure1_closerequestfcn, axis1_buttondownfcn. H is the callback object s handle (obtained using GCBO). EVENTDATA is empty, but reserved for future use. HANDLES is a structure containing handles of components in GUI using tags as fieldnames, e.g. handles.figure1, handles.slider2. This structure is created at GUI startup using GUIHANDLES and stored in the figure s application data using GUIDATA. A copy of the structure is passed to each callback. You can store additional information in this structure at GUI startup, and you can change the structure during callbacks. Call guidata(h, handles) after changing your copy to replace the stored original so that subsequent callbacks see the updates. Type help guihandles and help guidata for more information. VARARGIN contains any extra arguments you have passed to the callback. Specify the extra arguments by editing the callback property in the inspector. By default, GUIDE sets the property to: <MFILENAME>( <SUBFUNCTION_NAME>, gcbo, [], guidata(gcbo)) Add any extra arguments after the last argument, before the final closing parenthesis.
function varargout = edit1_callback(h, eventdata, handles, varargin) function varargout = pushbutton1_callback(h, eventdata, handles, varargin) f=2; R=4;r=2; m=20;l=10; theta=pi/2*(get(handles.slider1, value )) %val1=str2double(get(handles.p-edit1, string )) %set(handles,slider1, value,val1) [t,u]=ode45( gzfun,[0:0.001:5],[0,0],[],f,r,r,m,theta); x=r*u(:,1);y=r*ones(length(t),1); ll=l*ones(length(t),1);rr=r*ones(length(t),1); xa=x+rr*sin(theta);ya=y-rr*cos(theta); xb=xa+(ll+r*u(:,1))*cos(theta); yb=ya+(ll+r*u(:,1))*sin(theta); xc=x-r*sin(u(:,1));yc=y-r*cos(u(:,1)); xd=x-r*sin(u(:,1));yd=y-r*cos(u(:,1)); axis([-15,15,-2,10]); axis equal hold on a10=line([-15,15],[0,0], color, k, linewidth,3.5); a20=linspace(-15,15,60); for i=1:59 a30=(a20(i)+a20(i+1))/2; plot([a20(i),a30],[0,0-0.5], color, b,... linestyle, -, linewidth,1); fai=0:0.01:7;fai1=rot90(fai);yy=r*ones(length(fai),1); px=r*cos(fai1);py=yy+r*sin(fai1); qx=r*cos(fai1);qy=yy+r*sin(fai1); ball1=line(px,py, color, b, linewidth,2, erasemode, xor ); ball2=line(qx,qy, color, b, linewidth,2, erasemode, xor ); xian=line([xa(1),xb(1)],[ya(1),yb(1)], color, k,... gan=line([xc(1),xd(1)],[yc(1),yd(1)], color, k,... for i=1:length(t)
xx=x(i)*ones(length(fai),1); pxx=xx+r*cos(fai1);pyy=yy+r*sin(fai1); qxx=xx+r*cos(fai1);qyy=yy+r*sin(fai1); set(ball1, xdata,pxx, ydata,pyy); set(ball2, xdata,qxx, ydata,qyy); set(xian, xdata,[xa(i),xb(i)], ydata,... [ya(i),yb(i)]); set(gan, xdata,[xc(i),xd(i)], ydata,... [yc(i),yd(i)]); drawnow function udot=gzfun(t,u,flag,f,r,r,m,theta) %global f R r m theta udot=[u(2); 2*f*(R*cos(theta)-r)/3*m*(R^2)]; function varargout = pushbutton2_callback(h, eventdata, handles, varargin) edit jiemian function varargout = pushbutton3_callback(h, eventdata, handles, varargin) close function varargout = slider1_callback(h, eventdata, handles, varargin) val1=num2str(get(handles.slider1, value )) set(handles.edit2, string,val1) function varargout = edit2_callback(h, eventdata, handles, varargin) val2=str2double(get(handles.edit2, string )) set(handles.slider1, value,val2)
程序运行截图 : 图 1 正转 图 2 反转