2007年5月9日 星期三

第八次作業第ㄧ題

本題採用講義上之f4bar函式
分析出四連趕各桿位置,速度,加速度,然後取值

以下為函式的內容:

function [data,form] = f4bar(r,theta1,theta2,td2,tdd2,mode,linkdrive)
%輸入參數為
%r= [r1 r2 r3 r4]: 各桿之長度
%theta1= 桿一之水平角度
%theta2= 驅動桿(可為桿2或3)之水平角度
%td2= 驅動桿之角速度(rad/sec)
%tdd2= 驅動桿之角加速度(rad/sec^2)
%mode= +1 or -1 組合模數,負值表閉合型;正值表分支型
%linkdrive = 0表示驅動桿為第二桿; 1表示驅動桿為第三桿
if nargin<7,linkdrive=0;end mode="1;end" data="zeros(4,6);" linkdrive="=" r="[r(1)" rr="r.*r;d2g=" t1="theta(1);tx=" s1="sin(t1);c1=" sx="sin(tx);cx=" a="2*r(1)*r(4)*c1-2*r(2)*r(4)*cx;" c="rr(1)+rr(2)+rr(4)-rr(3)-2*r(1)*r(2)*(c1*cx+s1*sx);" b="2*r(1)*r(4)*s1-2*r(2)*r(4)*sx;" pos="B*B-C*C+A*A;">=0,
form=1;
% Check for the denominator equal to zero
if abs(C-A)>=1e-5
t4=2*atan((-B+mode*sqrt(pos))/(C-A));
s4=sin(t4);c4=cos(t4);
t3=atan2((r(1)*s1+r(4)*s4-r(2)*sx),(r(1)*c1+r(4)*c4-r(2)*cx));
s3=sin(t3);c3=cos(t3);
else
% If the denominator is zero, compute theta(3) first
A=-2*r(1)*r(3)*c1+2*r(2)*r(3)*cx;
B=-2*r(1)*r(3)*s1+2*r(2)*r(3)*sx;
C=rr(1)+rr(2)+rr(3)-rr(4)-2*r(1)*r(2)*(c1*cx+s1*sx);
pos=B*B-C*C+A*A;
if pos>=0,
t3=2*atan((-B-mode*sqrt(pos))/(C-A));
s3=sin(t3); c3=cos(t3);
t4=atan2((-r(1)*s1+r(3)*s3+r(2)*sx),...
(-r(1)*c1+r(3)*c3+r(2)*cx));
s4=sin(t4);c4=cos(t4);
end
end
theta(3)=t3;theta(4)=t4;
%velocity calculation
td(2)=td2;
AM=[-r(3)*s3, r(4)*s4; -r(3)*c3, r(4)*c4];
BM=[r(2)*td(2)*sx;r(2)*td(2)*cx];
CM=AM\BM;
td(3)=CM(1);td(4)=CM(2);

%acceleration calculation

tdd(2)=tdd2;
BM=[r(2)*tdd(2)*sx+r(2)*td(2)*td(2)*cx+r(3)*td(3)*td(3)*c3-...
r(4)*td(4)*td(4)*c4;r(2)*tdd(2)*cx-r(2)*td(2)*td(2)*sx-...
r(3)*td(3)*td(3)*s3+r(4)*td(4)*td(4)*s4];
CM=AM\BM;
tdd(3)=CM(1);tdd(4)=CM(2);
%store results in array data
% coordinates of P and Q
if linkdrive==1,
c2=c3;c3=cx;s2=s3;s3=sx;
r(2:3)=[r(3) r(2)];theta(2:3)=[theta(3) theta(2)];
td(2:3)=[td(3) td(2)];tdd(2:3)=[tdd(3) tdd(2)];
else
c2=cx;s2=sx;
end
for j=1:4,
data(j,1:4)=[r(j)*exp(i*theta(j)) theta(j)/d2g td(j) tdd(j)] ;
end % position vectors
data(1,5)=r(2)*td(2)*exp(i*theta(2));%velocity for point Q
data(2,5)=r(4)*td(4)*exp(i*theta(4));%velocity for point P
data(3,5)=r(2)*(i*tdd(2)-td(2)*td(2))*exp(i*theta(2));%acc of Q
data(4,5)=r(4)*(i*tdd(4)-td(4)*td(4))*exp(i*theta(4));%acc of P
data(1,6)=data(2,1);%position of Q, again
data(2,6)=data(1,1)+data(4,1);% position of P

%find the accelerations
else
form=0;
if linkdrive==1,
r=[r(1) r(3) r(2) r(4)];
for j=1:4, data(j,1)=r(j).*exp(i*theta(j));end % positions
end
end



%給定條件執行程式
>> [data,form]=f4bar([4 3 3 5],0,45,10,0,-1,0)

data =

1.0e+003 *

Columns 1 through 5

0.0040 0 0 0 0.0212 + 0.0212i
0.0021 + 0.0021i 0.0450 0.0100 0 0.0041 - 0.0245i
0.0011 + 0.0028i 0.0695 -0.0163 0.4914 -0.2121 - 0.2121i
-0.0008 + 0.0049i 0.0995 -0.0050 0.3836 -1.8712 - 0.4391i

Column 6

0.0021 + 0.0021i
0.0032 + 0.0049i
0
0

function dyad_draw([4 3 3 5],[0 45 69 99],[0 10 16.3 5],[0 0 491.4 383.6])

%column1: 各桿之位置向量(複數型式)
%column2: 各桿之水平夾角
%column3: 各桿之角速度
%column4: 各桿之角加速度
%column5-1: Q點之速度
%column5-2: P點之速度
%column5-3: Q點之加速度
%column5-4: P點之加速度
%column6-1: Q點之位置向量
%column6-2: P點之位置向量

form =

1

%form=1 表示此四連桿可構成,若為0 則表不行


由程式結果得到
O點位置: 0 + 0i
Q點位置: 0.0021 + 0.0021i
P點位置: 0.0032 + 0.0049i
R點位置: 0.0040 + 0i(同桿一)


>> abs(data(:,5))

ans =

1.0e+003 *

0.0300
0.0248
0.3000
1.9220

又對column5取絕對值後
Q點速度為0.03
P點速度為0.0248
R點和O點速度為0(因桿1為固定桿)
(速度單位為: 長度/時間)

同理
Q點加速度為0.3
p點加速度為1.9220
R點和O點加速度為0
(加速度為: 長度/時間^2)

第一桿:0.0040
第二桿:0.0021 + 0.0021i
第三桿:0.0011 + 0.0028i
第四桿:-0.0008 + 0.0049i
速度如下:
第一桿:0(rad/s)
第二桿:10.0000(rad/s)
第三桿:16.2681(rad/s)
第四桿:4.9677(rad/s)
加速度:
第一桿:0(rad/s*s)
第二桿:0(rad/s*s)
第三桿:491.4428(rad/s*s)
第四桿:383.6120(rad/s*s)

沒有留言: