本帖最后由 greenjvren 于 2015-5-6 13:15 编辑
L1=str2double(get(handles.edit1,'String'));
L2=str2double(get(handles.edit2,'String'));
L3=str2double(get(handles.edit3,'String'));
L4=str2double(get(handles.edit4,'String'));
L5=str2double(get(handles.edit5,'String'));
w2=str2double(get(handles.edit6,'String'));
l=str2double(get(handles.edit7,'String'));
i=str2double(get(handles.edit8,'String'));
th2=[0:2/72:2]*pi;
th5=i*pi;
th34=zeros(length(th2),2);
options=optimset('display','off');
for m=1:length(th2)
th34(m,:)=fsolve('fourbarposition',[1 1],options,th2(m),L2,L3,L4,L1);
end
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
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
val=get(hObject,'Value');
str=get(hObject,'String');
switch str{val}
case 'barposition of 3'
th2=[0:1/6:2]*pi;
th34=zeros(length(th2),2);
options=optimset('display','off');
for m=1:length(th2)
th34(m,:)=fsolve('fourbarposition',[1 1],options,th2(m),L2,L3,L4,L1);
end
y=L2*sin(th2)+L3*sin(th34(:,1)');
x=L2*cos(th2)+L3*cos(th34(:,1)');
xx=[L2*cos(th2)];
yy=[L2*sin(th2)];
plot([x;xx],[y;yy],'k',[0 L1],[0 0],'k--^',x,y,'ko',xx,yy,'ks')
title('barposition of 3')
xlabel('Horizontal direction ')
ylabel('Vertical direction')
axis equal
grid on
case 'barposition of 5'
th2=[0:1/24:2]*pi;
th34=zeros(length(th2),2);
options=optimset('display','off');
for m=1:length(th2)
th34(m,:)=fsolve('fourbarposition',[1 1],options,th2(m),L2,L3,L4,L1);
end
y1=L2*sin(th2)+l*sin(th34(:,1)')+L5*sin(th34(:,1)'+th5);
x1=L2*cos(th2)+l*cos(th34(:,1)')+L5*cos(th34(:,1)'+th5);
xx1=[L2*cos(th2)+l*cos(th34(:,1)')];
yy1=[L2*sin(th2)+l*sin(th34(:,1)')];
plot([x1;xx1],[y1;yy1],'k',[0 L1],[0 0],'k--^',x1,y1,'ko',xx1,yy1,'ks')
title('barposition of 5')
xlabel('Horizontal direction')
ylabel('Vertical direction')
axis equal
grid on
end
guidata(hObject,handles)
为什么 我加了不显示内容