您的当前位置:首页正文

用matlab分析四杆机构

2020-02-13 来源:好走旅游网
首先创建函数FoutBarPosition,函数fsolve通过他确定 。 function t=fourbarposition(th,th2,L2,L3,L4,L1) t=[L2*cos(th2)+L3*cos(th(1))-L4*cos(th(2))-L1;… L2*sin(th2)+L3*sin(th(1))-L4*sin(th(2))]; 主程序如下:

disp ' * * * * * * 平面四杆机构的运动分析 * * * * * *'

L1=304.8;L2=101.6;L3=254.0;L4=177.8; %给定已知量,各杆长L1,L2,L3,L4 th2=[0:1/6:2]*pi; %曲柄输入角度从0至360度,步长为pi/6

th34=zeros(length(th2),2); %建立一个N行2列的零矩阵,第一列存放options=optimset('display','off'); %θ_3,第二列存放θ_3 for m=1:length(th2) %建立for循环,求解θ_3,θ_4

th34(m,:)=fsolve('fourbarposition',[1 1],… %调用fsove函数求解关于θ_3,θ_4 options,th2(m),L2,L3,L4,L1); %的非线性超越方程,结果保存在th34中 end

y=L2*sin(th2)+L3*sin(th34(:,1)'); %连杆3的D端点Y坐标值 x=L2*cos(th2)+L3*cos(th34(:,1)'); %连杆3的D端点X坐标值 xx=[L2*cos(th2)]; %连杆3的C端点X坐标值 yy=[L2*sin(th2)]; %连杆3的C端点Y坐标值 figure(1)

plot([x;xx],[y;yy],'k',[0 L1],[0 0],… %绘制连杆3的几个位置点 'k--^',x,y,'ko',xx,yy,'ks') title('连杆3的几个位置点') xlabel('水平方向') ylabel('垂直方向') axis equal %XY坐标均衡

th2=[0:2/72:2]*pi; %重新细分曲柄输入角度θ_2,步长为5度 th34=zeros(length(th2),2); options=optimset('display','off'); for m=1:length(th2)

1 / 8

th34(m,:)=fsolve('fourbarposition',[1 1],… options,th2(m),L2,L3,L4,L1); end figure(2)

plot(th2*180/pi,th34(:,1),th2*180/pi,th34(:,2)) %绘制连杆3的角位移关于曲柄2的角位移图

plot(th2*180/pi,th34(:,1)*180/pi,…

th2*180/pi,th34(:,2)*180/pi) %绘制摇杆4的角位移关于曲柄2的角位移图 axis([0 360 0 170]) %确定XY边界值 grid %图形加网格

xlabel('主动件转角\heta_2(度)') ylabel('从动件角位移(度)') title('角位移线图')

text(120,120,'摇杆4角位移') text(150,40,'连杆3角位移') w2=250; %设定曲柄角速度 for i=1:length(th2)

A=[-L3*sin(th34(i,1)) L4*sin(th34(i,2));… L3*cos(th34(i,1)) -L4*cos(th34(i,2))]; B=[w2*L2*sin(th2(i)); -w2*L2*cos(th2(i))]; w=inv(A)*B; w3(i)=w(1); w4(i)=w(2); end figure(3)

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)')

2 / 8

grid

xlabel('主动件转角\heta_2(度)') ylabel('从动件角速度(rad\\cdot s^{-1})') title('角速度线图') for i=1:length(th2)

C=[-L3*sin(th34(i,1)) L4*sin(th34(i,2));… L3*cos(th34(i,1)) -L4*cos(th34(i,2))];

D=[w2^2*L2*cos(th2(i))+w3(i)^2*L3*cos(th34(i,1))-w4(i)^2*L4*cos(th34(i,2));... w2^2*L2*sin(th2(i))+w3(i)^2*L3*sin(th34(i,1))-w4(i)^2*L4*sin(th34(i,2))]; a=inv(C)*D; a3(i)=a(1); a4(i)=a(2); end figure(4)

plot(th2*180/pi,a3,th2*180/pi,a4); %绘制角加速度线图 axis([0 360 -70000 65000])

text(50,50000,'摇杆4角加速度(\\alpha_4)') text(220,12000,'连杆3角加速度(\\alpha_3)') grid

xlabel('从动件角加速度')

ylabel('从动件角加速度(rad\\cdot s^{-2})') title('角加速度线图')

disp '曲柄转角连杆转角-摇杆转角-连杆角速度-摇杆角速度-连杆加速度-摇杆加速度' ydcs=[th2'*180/pi,th34(:,1)*180/pi,th34(:,2)*180/pi,w3',w4',a3',a4']; disp(ydcs)

>> * * * * * * 平面四杆机构的运动分析 * * * * * *

曲柄转角 连杆转角-摇杆转角-连杆角速度-摇杆角速度-连杆加速度-摇杆加速度 1.0e+004 *

0 0.0044 0.0097 -0.0125 -0.0125 -0.5478 4.8458

3 / 8

0.0005 0.0042 0.0094 -0.0126 -0.0107 0.2300 5.5630 0.0010 0.0039 0.0092 -0.0124 -0.0086 0.8946 6.0520 0.0015 0.0037 0.0091 -0.0119 -0.0065 1.4143 6.2982 0.0020 0.0034 0.0090 -0.0114 -0.0043 1.7801 6.3174 0.0025 0.0032 0.0089 -0.0107 -0.0021 2.0027 6.1467 0.0030 0.0030 0.0089 -0.0100 0.0000 2.1046 5.8339 0.0035 0.0028 0.0089 -0.0093 0.0020 2.1134 5.4272 0.0040 0.0026 0.0090 -0.0085 0.0038 2.0566 4.9687 0.0045 0.0025 0.0091 -0.0078 0.0054 1.9578 4.4918 0.0050 0.0023 0.0092 -0.0072 0.0069 1.8356 4.0198 0.0055 0.0022 0.0093 -0.0065 0.0082 1.7040 3.5680 0.0060 0.0021 0.0095 -0.0060 0.0094 1.5725 3.1450 0.0065 0.0019 0.0097 -0.0055 0.0104 1.4474 2.7545 0.0070 0.0018 0.0099 -0.0050 0.0113 1.3328 2.3968 0.0075 0.0017 0.0102 -0.0045 0.0121 1.2307 2.0702 0.0080 0.0017 0.0104 -0.0041 0.0128 1.1425 1.7716 0.0085 0.0016 0.0107 -0.0037 0.0134 1.0687 1.4971 0.0090 0.0015 0.0110 -0.0034 0.0138 1.0095 1.2426 0.0095 0.0014 0.0112 -0.0030 0.0142 0.9653 1.0035 0.0100 0.0014 0.0115 -0.0027 0.0145 0.9364 0.7752 0.0105 0.0013 0.0118 -0.0024 0.0148 0.9232 0.5530 0.0110 0.0013 0.0121 -0.0020 0.0149 0.9269 0.3319 0.0115 0.0013 0.0124 -0.0017 0.0150 0.9485 0.1069 0.0120 0.0012 0.0127 -0.0014 0.0150 0.9899 -0.1276 0.0125 0.0012 0.0130 -0.0010 0.0149 1.0530 -0.3773 0.0130 0.0012 0.0133 -0.0006 0.0147 1.1404 -0.6481 0.0135 0.0012 0.0136 -0.0002 0.0145 1.2544 -0.9455 0.0140 0.0012 0.0139 0.0002 0.0141 1.3967 -1.2743 0.0145 0.0012 0.0142 0.0008 0.0136 1.5677 -1.6368

4 / 8

0.0150 0.0012 0.0144 0.0013 0.0129 1.7648 -2.0314 0.0155 0.0012 0.0147 0.0020 0.0121 1.9807 -2.4495 0.0160 0.0013 0.0149 0.0027 0.0112 2.2018 -2.8735 0.0165 0.0013 0.0151 0.0035 0.0101 2.4071 -3.2754 0.0170 0.0014 0.0153 0.0044 0.0089 2.5697 -3.6186 0.0175 0.0015 0.0155 0.0053 0.0076 2.6616 -3.8650 0.0180 0.0016 0.0156 0.0063 0.0063 2.6609 -3.9849 0.0185 0.0018 0.0157 0.0072 0.0049 2.5591 -3.9674 0.0190 0.0019 0.0158 0.0080 0.0035 2.3638 -3.8244 0.0195 0.0021 0.0159 0.0088 0.0022 2.0959 -3.5866 0.0200 0.0023 0.0159 0.0095 0.0010 1.7823 -3.2931 0.0205 0.0025 0.0159 0.0100 -0.0001 1.4487 -2.9815 0.0210 0.0027 0.0159 0.0105 -0.0011 1.1152 -2.6809 0.0215 0.0029 0.0159 0.0108 -0.0020 0.7942 -2.4103 0.0220 0.0031 0.0158 0.0111 -0.0028 0.4916 -2.1794 0.0225 0.0033 0.0158 0.0112 -0.0035 0.2086 -1.9913 0.0230 0.0036 0.0157 0.0112 -0.0042 -0.0565 -1.8450 0.0235 0.0038 0.0156 0.0111 -0.0048 -0.3071 -1.7375 0.0240 0.0040 0.0155 0.0110 -0.0054 -0.5475 -1.6650 0.0245 0.0042 0.0154 0.0108 -0.0060 -0.7817 -1.6233 0.0250 0.0044 0.0153 0.0104 -0.0065 -1.0139 -1.6089 0.0255 0.0046 0.0151 0.0100 -0.0071 -1.2479 -1.6181 0.0260 0.0048 0.0150 0.0096 -0.0077 -1.4868 -1.6480 0.0265 0.0050 0.0148 0.0090 -0.0082 -1.7336 -1.6955 0.0270 0.0052 0.0146 0.0084 -0.0088 -1.9905 -1.7574 0.0275 0.0054 0.0145 0.0076 -0.0095 -2.2588 -1.8304 0.0280 0.0055 0.0143 0.0068 -0.0101 -2.5391 -1.9100 0.0285 0.0056 0.0141 0.0058 -0.0108 -2.8305 -1.9910 0.0290 0.0057 0.0138 0.0048 -0.0115 -3.1300 -2.0660

5 / 8

0.0295 0.0058 0.0136 0.0037 -0.0122 -3.4326 -2.1255 0.0300 0.0059 0.0133 0.0024 -0.0130 -3.7297 -2.1572 0.0305 0.0059 0.0131 0.0011 -0.0137 -4.0091 -2.1451 0.0310 0.0059 0.0128 -0.0004 -0.0145 -4.2538 -2.0696 0.0315 0.0059 0.0125 -0.0019 -0.0152 -4.4419 -1.9079 0.0320 0.0058 0.0122 -0.0035 -0.0158 -4.5473 -1.6352 0.0325 0.0058 0.0119 -0.0051 -0.0163 -4.5411 -1.2273 0.0330 0.0056 0.0115 -0.0066 -0.0166 -4.3954 -0.6661 0.0335 0.0055 0.0112 -0.0081 -0.0167 -4.0889 0.0551 0.0340 0.0053 0.0109 -0.0095 -0.0166 -3.6129 0.9243 0.0345 0.0051 0.0105 -0.0106 -0.0161 -2.9781 1.9058 0.0350 0.0049 0.0102 -0.0115 -0.0152 -2.2178 2.9395 0.0355 0.0047 0.0099 -0.0122 -0.0140 -1.3857 3.9473 0.0360 0.0044 0.0097 -0.0125 -0.0125 -0.5478 4.8458 图形输出:

图2 连杆3的几个位置点

6 / 8

图4 角加速度线图

7 / 8

图5 角加速度线图

8 / 8

因篇幅问题不能全部显示,请点此查看更多更全内容