How to optimise 4 bar mechanism using constraints and penalty

4 views (last 30 days)
I have got transmission angle constraints, grashof criteria and variable bounds I want to optimised a 4 bar linkage using genetic algorithm. I also want to know how to convert from vector to scalar.
These are my constraints and variable bounds if someone please give me an example of how to do it with these it would be amazing, (submission in two days)
function [obj,const]=pathec1(X)
% objective square error
% DESIRED X AND Y POSITIONS (6 POINT PROBLEM)
pxd=[20 20 20 20 20 20];
pyd=[20 25 30 35 40 45];
error=0;
% Grashof's criteria
LS=min([X(1),X(2),X(3),X(4)]);
LL=max([X(1),X(2),X(3),X(4)]);
if (2*(LS+LL)>X(1)+X(2)+X(3)+X(4))
CV1=1;%(2*(LS+LL))/(X(1)+X(2)+X(3)+X(4))-1;
else
CV1=0;
end
% angle sequence constraint
CV2=0;
j1=7;
while j1<12
if (X(j1+1)-X(j1))<0
CV2=1;
break;
else
j1=j1+1;
end
end
% TRANSMISSION ANGLE constraints (MU_MIN<MU<MU_MAX)
u_min=acos((X(2)^2+X(3)^2-(X(4)-X(1))^2)/(2*X(2)*X(3)));
u_max=acos((X(2)^2+X(3)^2-(X(4)+X(1))^2)/(2*X(2)*X(3)));
CV3=0;
CV4=0;
for i1=1:6
nume=X(1)^2+X(4)^2-X(2)^2-X(3)^2-2*X(1)*X(4)*cos(X(i1+6));
deno=(-2*X(2)*X(3));
u(i1)=acos(nume/deno);
g2=(u_min/u(i1))-1;
g3=(u(i1)/u_min)-1;
if g2>0
CV3_P=g2;
else
CV3_P=0;
end
if g3>0
CV4_P=g3;
else
CV4_P=0;
end
CV3=CV3+CV3_P;
CV4=CV4+CV4_P;
end
const=1000*(CV1+CV2);%+CV3+CV4);
k1=X(4)/X(1);k2=X(4)/X(3);k3=(X(1)^2+X(3)^2+X(4)^2-X(2)^2)/(2*X(1)*X(3));
k4=X(4)/X(2);k5=(-X(1)^2+X(3)^2-X(4)^2-X(2)^2)/(2*X(1)*X(2));
R=[cos(X(13)) -sin(X(13));sin(X(13)) cos(X(13))];
T=[X(14);X(15)];
j2=6;
while j2<12
E=-2*sin(X(j2+1));D=cos(X(j2+1))-k1+k4*cos(X(j2+1))+k5;
F=k1+(k4-1)*cos(X(j2+1))+k5;i1=j2+1;
if E^2-4*D*F<0
px1=1e10;py1=1e10;px2=1e10;py2=1e10;
else
theta_31=2*atan((-E+sqrt(E^2-4*D*F))/(2*D));
theta_32=2*atan((-E-sqrt(E^2-4*D*F))/(2*D));
px1=X(1)*cos(X(i1))+X(5)*cos(theta_31)-X(6)*sin(theta_31);
py1=X(1)*sin(X(i1))+X(5)*sin(theta_31)+X(6)*cos(theta_31);
px2=X(1)*cos(X(i1))+X(5)*cos(theta_32)-X(6)*sin(theta_32);
py2=X(1)*sin(X(i1))+X(5)*sin(theta_32)+X(6)*cos(theta_32);
end
P1=[px1;py1]; P2=[px2;py2];
P01=R*P1+T;P02=R*P2+T;
px01=P01(1);py01=P01(2);px02=P02(1);py02=P02(2);
E1=(pxd(i1-6)-px01)^2+(pyd(i1-6)-py01)^2;
E2=(pxd(i1-6)-px02)^2+(pyd(i1-6)-py02)^2;
Er=min([E1 E2]);
error=error+Er;
j2=j2+1;
end
obj=error;

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!