The past is still the past.
My favorite faded fantasy.
機構學的作業,不知道能不能被搜索引擎索引到(可能會有學弟學妹能看到吧)。
matlab現學現賣。
在已知輸入角度的情況下,確定餘下桿件的角度位置。
原理是泰勒展開和Newton-Raphson's Method進行循環迭代,使角度逼近于真實值。
1.题目定义
有一個四連桿組,如圖所示,杆2為輸入杆,且r1=a0b0=6,r2=a0a=2,r3=ab=5,r4=b0b=5,r3p=ac=2.5。2.数学式
3.完整程式
r1=6;r2=2;r3=5;r4=5;r3p=2.5;t3=70*pi/180;t4=120*pi/180;
i=0;disp(' θ2 θ3 θ4 Xc Yc ')
for t2=0:10*pi/180:2*pi %t2在0到2pi每間隔10度取一次值
dt3=1;dt4=1; %給dt3,dt4定義一個初值,使循環能夠開始
while ((abs(dt3)>10^(-6))||(abs(dt4)>10^(-6))) %使用Newton-Raphson’s method 迭代逼近,到dt3、dt4小於10^(-6)時跳出回圈。
e1=r2*cos(t2)+r3*cos(t3)-r4*cos(t4)-r1;
e2=r2*sin(t2)+r3*sin(t3)-r4*sin(t4);
dt3=(e1*cos(t4)+e2*sin(t4))/(r3*sin(t3-t4));
dt4=(e1*cos(t3)+e2*sin(t3))/(r4*sin(t3-t4));
t3=t3+dt3;t4=t4+dt4;
end
x1=[0:0.01:6]; %根據已知數據,寫出四根杆的函數並畫出圖像
y1=0*x1;
if (t2>=pi/2)&&(t2<=1.5*pi) %防止出現因爲cos(t2)小于0,導致x2向量為空集的情況
x2=[r2*cos(t2):0.01:0];
else
x2=[0:0.01:r2*cos(t2)];
end
y2=tan(t2)*x2;
x3=[r2*cos(t2):0.01:6+r4*cos(t4)];
y3=tan(t3)*(x3-r2*cos(t2))+r2*sin(t2);
x4=[6+r4*cos(t4):0.01:6];
y4=tan(t4)*(x4-6);
plot(x1,y1,x2,y2,x3,y3,x4,y4) %畫出四根杆的函數圖像
D=[t2 t3 t4 r2*cos(t2)+0.5*r3*cos(t3)r2*sin(t2)+0.5*r3*sin(t3)];
disp(D) %輸出計算結果
i=i+1;
m(i)=getframe; %對每一個t2值,截取畫出的圖像並作爲一幀
end
movie (m) %使取得的每一幀圖像播放成動畫