首页 > 编程知识 正文

曲柄摇杆机构MATLAB程序

时间:2023-05-05 11:55:25 阅读:220775 作者:723

function popupmenu1_Callback(hObject,handles)
% hObject
handle to popupmenu1 (see GCBO)
% eventdata
reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)


% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%
contents{get(hObject,'Value')} returns selected item from popupmenu1


%从编辑框获取数据
L1=str2double(get(handles.edit1,'String'));
L2=str2double(get(handles.edit2,'String'));
L3=str2double(get(handles.edit3,'String'));
L4=str2double(get(handles.edit4,'String'));
w2=str2double(get(handles.edit5,'String'));
th2=0:0.01:2*pi; %θ2的范围为0到2π
th34=zeros(length(th2),2);%建立一个length(th2)行2列的零矩阵,第一列存放θ_3,第二列存放θ_4
options=optimset('display','off');%创建options结构变量,其中display的值为off,表示函数调用时中间结果不显示。
for m=1:length(th2)%建立for循环,求解θ_3,θ_4
th34(m,:)=fsolve(@Qbyg_01,[1 1],options,th2(m),L2,L3,L4,L1);%调用fsolve函数求解关于θ_3,θ_4
end


for n=1:length(th2)%建立角速度矩阵形式
A=[-L3*sin(th34(n,1)) L4*sin(th34(n,2)); L3*cos(th34(n,1)) -L4*cos(th34(n,2))];
B=[w2*L2*sin(th2(n)); -w2*L2*cos(th2(n))];
w=inv(A)*B;%利用矩阵求w3,w4
w3(n)=w(1);
w4(n)=w(2);
end


for n=1:length(th2)%建立角加速度矩阵形式
C=[-L3*sin(th34(n,1)) L4*sin(th34(n,2));L3*cos(th34(n,1)) -L4*cos(th34(n,2))];
D=[w2^2*L2*cos(th2(n))+w3(n)^2*L3*cos(th34(n,1))-w4(i)^2*L4*cos(th34(n,2));...
w2^2*L2*sin(th2(n))+w3(n)^2*L3*sin(th34(n,1))-w4(n)^2*L4*sin(th34(n,2))];
a=inv(C)*D;%利用矩阵求a2,a3
a3(n)=a(1);
a4(n)=a(2);
end


val=get(handles.popupmenu1,'value');
axes(handles.axes1);
switch val


case 1


plot(th2*180/pi,w3,th2*180/pi,w4);
axis([0 360 -175 200])
text(50,160,'摇杆4角速度(omega_4)')
text(220,130,'连杆3角速度(omega_3)')
grid on
xlabel('曲柄转角theta_2(度)')
ylabel('摇杆角速度(radcdot s^{-1})')
title('角速度线图')


case 2


plot(th2*180/pi,a3,th2*180/pi,a4); 
axis([0 360 -50000 65000])
text(50,50000,'摇杆4角加速度(alpha_4)')
text(220,12000,'连杆3角加速度(alpha_3)')
grid on
xlabel('曲柄转角theta_2(度)')
ylabel('摇杆角加速度(radcdot s^{-2})')
title('角加速度线图')


case 3


plot(th2*180/pi,th34(:,1)*180/pi,th2*180/pi,th34(:,2)*180/pi)
axis([0 360 0 170])
grid on
xlabel('曲柄转角theta_2(度)')
ylabel('摇杆角位移(度)')
title('角位移线图')
text(120,120,'摇杆4角位移')
text(150,40,'连杆3角位移')
   
end
guidata(hObject,handles)
%其中,guidata(hObject,handles)命令用于更新句柄,当输入不同参数是,程序能够做出相应的相应。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。