曲柄摇杆机构MATLAB程序

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('摇杆角速度(rad\cdot 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('摇杆角加速度(rad\cdot 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)命令用于更新句柄,当输入不同参数是,程序能够做出相应的相应。
  • 13
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值