//2016/第二次小考
r1=6; r2=2.5; r3=10; r4=7; theta2deg=60; theta2=60*%pi/180; theta2d=40;
theta2dd=0;//命名各式變數,包含課本中公解需要用到的 h,b,d,e
h1=(r1/r2); h3=(r1/r4); h5=((r1^2+r2^2-r3^2+r4^2)/(2*r2*r4));//命名各式變數,包含課本中公解需要用到的 h,b,d,e
b=-2*sin(theta2); d=-h1+(1-h3)*cos(theta2)+h5; e=h1-(1+h3)*cos(theta2)+h5;//命名各式變數,包含課本中公解需要用到的
h,b,d,e
for i=1;//建立一個迴圈來解兩分支
theta4(i)=2*atan(-b-(-1)^i*sqrt(b^2-4*d*e),(2*d));//透過(-1)^i 來改變執行兩分支時帶入的公式
if theta4(i)<0 then theta4(i)=theta4(i)+2*%pi end;//確保角四的值恆正(只是為了方便閱讀)
theta4deg(i)=theta4(i)*(180/%pi); //把角四的值改成以度計算(只是為了方便閱讀)
theta3(i)=atan(r4*sin(theta4(i))-r2*sin(theta2),(r4*cos(theta4(i))-
r2*cos(theta2)+r1));//以公式解出角三
if theta3(i)<0 then theta3(i)=theta3(i)+2*%pi end;//確保角三的值恆正(只是為了方便閱讀)
theta3deg(i)=theta3(i)*(180/%pi);//把角三的值改成以度計算(只是為了方便閱讀)
//theta4(i)=0;//可以故意假設一個明顯有錯的角四來確保下行驗算機制效(可以說是驗算的)
if (r4*sin(theta4(i))-r3*sin(theta3(i))-r2*sin(theta2))^2<0.01 then disp ("correct")
else disp ("wrong") end;//驗算出來的角三似是否真可以帶入向量迴路方程,且誤差平小於零點一如果驗後結正確會輸correct
A(1,1) = r3*sin(theta3(i));//創造一個可以解出theta3d theta4d 的矩陣
A(1,2) = -r4*sin(theta4(i));//創造一個可以解出theta3d theta4d 的矩陣
A(2,1) = r3*cos(theta3(i));//創造一個可以解出theta3d theta4d 的矩陣
A(2,2) = -r4*cos(theta4(i));//創造一個可以解出theta3d theta4d 的矩陣
b(1) = -r2*theta2d*sin(theta2);//創造一個可以解出theta3d theta4d 的矩陣
b(2)= -r2*theta2d*cos(theta2);//創造一個可以解出theta3d theta4d 的矩陣
x = A\b;//解出角加速度
theta3d(i) = x(1);//存入值
theta4d(i) = x(2);//存入值
c(1) = -r2*theta2dd*sin(theta2(i)) - r2*theta2d^2*cos(theta2(i)) -
r3*theta3d(i)^2*cos(theta3(i)) + r4*theta4d(i)^2*cos(theta4(i));//創造一個可以解出theta3dd theta4dd 的矩陣
c(2) = -r2*theta2dd*cos(theta2(i)) + r2*theta2d^2*sin(theta2(i)) +
r3*theta3d(i)^2*sin(theta3(i)) - r4*theta4d(i)^2*sin(theta4(i));//創造一個可以解出theta3dd theta4dd 的矩陣
x = A\c;//解出角加速度
theta3dd(i) = x(1);//存入值
theta4dd(i) = x(2);//存入值
end;//結束迴圈
r1=6; r2=2.5; r3=10; r4=7; theta2deg=60; theta2=60*%pi/180; theta2d=40;
theta2dd=0;//命名各式變數,包含課本中公解需要用到的 h,b,d,e
h1=(r1/r2); h3=(r1/r4); h5=((r1^2+r2^2-r3^2+r4^2)/(2*r2*r4));//命名各式變數,包含課本中公解需要用到的 h,b,d,e
b=-2*sin(theta2); d=-h1+(1-h3)*cos(theta2)+h5; e=h1-(1+h3)*cos(theta2)+h5;//命名各式變數,包含課本中公解需要用到的
h,b,d,e
for i=1;//建立一個迴圈來解兩分支
theta4(i)=2*atan(-b-(-1)^i*sqrt(b^2-4*d*e),(2*d));//透過(-1)^i 來改變執行兩分支時帶入的公式
if theta4(i)<0 then theta4(i)=theta4(i)+2*%pi end;//確保角四的值恆正(只是為了方便閱讀)
theta4deg(i)=theta4(i)*(180/%pi); //把角四的值改成以度計算(只是為了方便閱讀)
theta3(i)=atan(r4*sin(theta4(i))-r2*sin(theta2),(r4*cos(theta4(i))-
r2*cos(theta2)+r1));//以公式解出角三
if theta3(i)<0 then theta3(i)=theta3(i)+2*%pi end;//確保角三的值恆正(只是為了方便閱讀)
theta3deg(i)=theta3(i)*(180/%pi);//把角三的值改成以度計算(只是為了方便閱讀)
//theta4(i)=0;//可以故意假設一個明顯有錯的角四來確保下行驗算機制效(可以說是驗算的)
if (r4*sin(theta4(i))-r3*sin(theta3(i))-r2*sin(theta2))^2<0.01 then disp ("correct")
else disp ("wrong") end;//驗算出來的角三似是否真可以帶入向量迴路方程,且誤差平小於零點一如果驗後結正確會輸correct
A(1,1) = r3*sin(theta3(i));//創造一個可以解出theta3d theta4d 的矩陣
A(1,2) = -r4*sin(theta4(i));//創造一個可以解出theta3d theta4d 的矩陣
A(2,1) = r3*cos(theta3(i));//創造一個可以解出theta3d theta4d 的矩陣
A(2,2) = -r4*cos(theta4(i));//創造一個可以解出theta3d theta4d 的矩陣
b(1) = -r2*theta2d*sin(theta2);//創造一個可以解出theta3d theta4d 的矩陣
b(2)= -r2*theta2d*cos(theta2);//創造一個可以解出theta3d theta4d 的矩陣
x = A\b;//解出角加速度
theta3d(i) = x(1);//存入值
theta4d(i) = x(2);//存入值
c(1) = -r2*theta2dd*sin(theta2(i)) - r2*theta2d^2*cos(theta2(i)) -
r3*theta3d(i)^2*cos(theta3(i)) + r4*theta4d(i)^2*cos(theta4(i));//創造一個可以解出theta3dd theta4dd 的矩陣
c(2) = -r2*theta2dd*cos(theta2(i)) + r2*theta2d^2*sin(theta2(i)) +
r3*theta3d(i)^2*sin(theta3(i)) - r4*theta4d(i)^2*sin(theta4(i));//創造一個可以解出theta3dd theta4dd 的矩陣
x = A\c;//解出角加速度
theta3dd(i) = x(1);//存入值
theta4dd(i) = x(2);//存入值
end;//結束迴圈