function [c,ceq]=FiveBar(x)
%,Disp1,Disp2,Disp4,Disp5
E0=6.895e4;
E=E0*ones(5,1);
A=[x(1) x(4) x(5) x(2) x(3)];
L=[254 254 254 254*2^0.5 254*2^0.5];

KE(:,:,1)=E(1)*A(1)/L(1)*[1 -1;-1 1];
KE(:,:,2)=E(2)*A(2)/L(2)*[1 -1;-1 1];
KE(:,:,3)=E(3)*A(3)/L(3)*[1 -1;-1 1];
KE(:,:,4)=E(4)*A(4)/L(4)*[1 -1;-1 1];
KE(:,:,5)=E(5)*A(5)/L(5)*[1 -1;-1 1];

T(:,:,1)=[1 0 0 0;0 0 1 0];
T(:,:,2)=[0 1 0 0;0 0 0 1];
T(:,:,3)=[-1 0 0 0;0 0 -1 0];
T(:,:,4)=[L(1)/L(4) L(2)/L(4) 0 0;0 0 L(1)/L(4) L(2)/L(4)];
T(:,:,5)=[-L(1)/L(5) L(2)/L(4) 0 0;0 0 -L(1)/L(4) L(2)/L(4)];

Kglobal=zeros(8,8);
edof = [1 2 3 4;3 4 5 6;5 6 7 8;1 2 5 6;3 4 7 8];
freedof = [3 4 5 6];
for i=1:5
    Kglobal(edof(i,:),edof(i,:))=Kglobal(edof(i,:),edof(i,:))+T(:,:,i)'*KE(:,:,i)*T(:,:,i);
end
F = [0 0 22.241e3 -13.344e3 0 4.448e3 0 0]';
U=zeros(8,1);
U(freedof) = Kglobal(freedof,freedof)\F(freedof);

Strain_ele=[(U(3)-U(1))/L(1);
             (U(6)-U(4))/L(2);
             (U(5)-U(7))/L(3);
             ((U(5)-U(1))*cos(45*pi/180)+(U(6)-U(2))*cos(45*pi/180))/L(4);
            ((U(3)-U(7))*cos(45*pi/180)+(U(8)-U(4))*cos(45*pi/180))/L(5)];
Stress_ele=[E(1);E(2);E(3);E(4);E(5)].*Strain_ele;

MaxStress=max(abs(Stress_ele))/413.684-1;
Disp1=((U(3)^2)^0.5)/1.524-1;
Disp2=((U(4)^2)^0.5)/1.524-1;
Disp3=((U(5)^2)^0.5)/1.524-1;
Disp4=((U(6)^2)^0.5)/1.524-1;
c=[MaxStress;Disp1;Disp2;Disp3;Disp4];
% c=MaxStress;
ceq=[];
max(abs(Stress_ele));
[U(3);
U(4);
U(5);
U(6)];