当前位置:文档之家› 用matlab分析四杆机构

用matlab分析四杆机构

首先创建函数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,L4th2=[0:1/6:2]*pi; %曲柄输入角度从0至360度,步长为pi/6th34=zeros(length(th2),2); %建立一个N行2列的零矩阵,第一列存放options=optimset('display','off'); %θ_3,第二列存放θ_3for m=1:length(th2) %建立for循环,求解θ_3,θ_4th34(m,:)=fsolve('fourbarposition',[1 1],…%调用fsove函数求解关于θ_3,θ_4options,th2(m),L2,L3,L4,L1); %的非线性超越方程,结果保存在th34中endy=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');form=1:length(th2)th34(m,:)=fsolve('fourbarposition',[1 1],…options,th2(m),L2,L3,L4,L1);endfigure(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([0360 0170])%确定XY边界值grid %图形加网格xlabel('主动件转角\theta_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);endfigure(3)plot(th2*180/pi,w3,th2*180/pi,w4); %绘制角速度线图axis([0 360 -175200])text(50,160,'摇杆4角速度(\omega_4)')text(220,130,'连杆3角速度(\omega_3)')gridxlabel('主动件转角\theta_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);endfigure(4)plot(th2*180/pi,a3,th2*180/pi,a4); %绘制角加速度线图axis([0360-70000 65000])text(50,50000,'摇杆4角加速度(\alpha_4)')text(220,12000,'连杆3角加速度(\alpha_3)')gridxlabel('从动件角加速度')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 *00.0044 0.0097 -0.0125 -0.0125-0.5478 4.84580.0005 0.0042 0.0094 -0.0126 -0.0107 0.2300 5.56300.0010 0.0039 0.0092 -0.0124 -0.00860.8946 6.05200.0015 0.0037 0.0091 -0.0119-0.0065 1.4143 6.29820.00200.0034 0.0090-0.0114 -0.0043 1.7801 6.31740.0025 0.0032 0.0089-0.0107-0.0021 2.0027 6.14670.0030 0.0030 0.0089 -0.0100 0.0000 2.1046 5.83390.0035 0.0028 0.0089 -0.0093 0.0020 2.1134 5.42720.00400.0026 0.0090 -0.00850.0038 2.0566 4.96870.0045 0.0025 0.0091 -0.00780.0054 1.9578 4.4918 0.00500.00230.0092 -0.0072 0.0069 1.8356 4.01980.00550.0022 0.0093 -0.00650.0082 1.7040 3.56800.00600.0021 0.0095 -0.0060 0.0094 1.5725 3.14500.0065 0.00190.0097 -0.0055 0.0104 1.4474 2.75450.00700.0018 0.0099 -0.00500.0113 1.33282.39680.0075 0.00170.0102 -0.00450.0121 1.2307 2.07020.0080 0.0017 0.0104-0.0041 0.0128 1.1425 1.77160.0085 0.00160.0107 -0.0037 0.0134 1.0687 1.49710.0090 0.0015 0.0110 -0.00340.0138 1.0095 1.24260.0095 0.0014 0.0112 -0.0030 0.0142 0.96531.00350.0100 0.0014 0.0115 -0.00270.0145 0.9364 0.77520.01050.0013 0.0118 -0.0024 0.0148 0.92320.5530 0.0110 0.00130.0121-0.0020 0.0149 0.9269 0.33190.01150.0013 0.0124 -0.0017 0.0150 0.9485 0.10690.0120 0.00120.0127 -0.0014 0.0150 0.9899-0.12760.01250.0012 0.0130 -0.0010 0.0149 1.0530 -0.37730.0130 0.0012 0.0133 -0.00060.0147 1.1404 -0.64810.0135 0.0012 0.0136 -0.0002 0.0145 1.2544 -0.94550.0140 0.0012 0.01390.0002 0.0141 1.3967 -1.27430.0145 0.00120.0142 0.0008 0.0136 1.5677 -1.6368 0.0150 0.0012 0.0144 0.0013 0.0129 1.7648 -2.03140.0155 0.0012 0.01470.00200.01211.9807 -2.4495 0.0160 0.0013 0.0149 0.00270.0112 2.2018 -2.8735 0.0165 0.0013 0.01510.00350.0101 2.4071-3.2754 0.01700.0014 0.0153 0.0044 0.0089 2.5697 -3.6186 0.0175 0.00150.01550.0053 0.0076 2.6616 -3.8650 0.0180 0.00160.01560.0063 0.0063 2.6609-3.9849 0.0185 0.0018 0.01570.0072 0.0049 2.5591 -3.96740.0190 0.0019 0.01580.0080 0.0035 2.3638 -3.82440.0195 0.0021 0.0159 0.0088 0.0022 2.0959 -3.58660.0200 0.00230.0159 0.0095 0.0010 1.7823 -3.2931 0.0205 0.00250.0159 0.0100 -0.0001 1.4487-2.9815 0.0210 0.0027 0.0159 0.0105-0.0011 1.1152-2.68090.0215 0.0029 0.0159 0.0108 -0.0020 0.7942-2.41030.0220 0.00310.0158 0.0111 -0.0028 0.4916 -2.17940.0225 0.0033 0.01580.0112 -0.0035 0.2086 -1.9913 0.02300.0036 0.01570.0112 -0.0042 -0.0565-1.84500.0235 0.0038 0.0156 0.0111 -0.0048 -0.3071 -1.73750.02400.0040 0.0155 0.0110-0.0054 -0.5475-1.66500.0245 0.0042 0.0154 0.0108 -0.0060-0.7817 -1.6233 0.0250 0.00440.01530.0104 -0.0065 -1.0139-1.6089 0.0255 0.0046 0.0151 0.0100-0.0071 -1.2479-1.61810.02600.0048 0.0150 0.0096-0.0077 -1.4868-1.6480 0.0265 0.00500.0148 0.0090 -0.0082-1.7336-1.69550.0270 0.00520.01460.0084 -0.0088-1.9905 -1.7574 0.02750.00540.0145 0.0076 -0.0095 -2.2588 -1.83040.0280 0.0055 0.0143 0.0068 -0.0101 -2.5391 -1.9100 0.0285 0.0056 0.01410.0058 -0.0108 -2.8305 -1.99100.0290 0.0057 0.0138 0.0048 -0.0115 -3.1300 -2.06600.02950.0058 0.01360.0037 -0.0122 -3.4326-2.1255 0.0300 0.0059 0.01330.0024 -0.0130 -3.7297 -2.15720.0305 0.00590.01310.0011 -0.0137 -4.0091 -2.1451 0.0310 0.00590.0128 -0.0004 -0.0145 -4.2538-2.06960.0315 0.0059 0.0125 -0.0019 -0.0152 -4.4419 -1.90790.0320 0.0058 0.0122 -0.0035 -0.0158 -4.5473 -1.63520.0325 0.0058 0.0119-0.0051 -0.0163 -4.5411 -1.2273 0.03300.0056 0.0115 -0.0066 -0.0166 -4.3954-0.66610.0335 0.0055 0.0112 -0.0081 -0.0167-4.08890.05510.03400.00530.0109 -0.0095 -0.0166 -3.6129 0.9243 0.03450.0051 0.0105 -0.0106 -0.0161 -2.9781 1.90580.0350 0.0049 0.0102-0.0115 -0.0152-2.2178 2.9395 0.03550.0047 0.0099-0.0122 -0.0140 -1.3857 3.94730.0360 0.0044 0.0097 -0.0125 -0.0125 -0.5478 4.8458图形输出:图2 连杆3的几个位置点图4 角加速度线图图5 角加速度线图。

相关主题