function [f, ce, ci] = FUN(x)
 
% Modification on Koski's truss problem
% Min vol and max of stresses 

A1 = x(1); A2 = x(2); A3 = x(3); %cross sectional areas 
xpos = x(4); % position of the middle bar in ft.
t = x(5); a = x(6);
u = x(7); y = x(8); % horizontal and vertical displacement in ft.
maxstress = x(9);
 
scal_fac = 5e-2;

% Constants
E = 29e3;% ksi
W = 1000;% kips
P = 100;% kips
L = 60;
D = 2*L;
  
f = 1;


F1 = E*A1*sin(t)*(y*sin(t) + u*cos(t))/L;
F2 = E*A2*y/L;
F3 = E*A3*sin(a)*(y*sin(a) - u*cos(a))/L;
   
ce = ones(4,1); 

% Force equilibrium for vertical load
 
ce(1) = F1*sin(t) + F2 + F3*sin(a) - W;

% Force equilibrium for horizontal load

ce(2) = P - F1*cos(t) + F3*cos(a); 

% Connectivity at O
ce(3) = xpos - L*cot(t);
ce(4) = xpos + L*cot(a) -D;

 
% Bounds on abs value of each stress by maxstress (being minimized)
ci = zeros(6,1);

ci(1) = F1 - maxstress*A1;
ci(2) = - F1 - maxstress*A1;  

ci(3) = F2 - maxstress*A2;
ci(4) = -F2 - maxstress*A2;

ci(5) = F3 - maxstress*A3;
ci(6) = -F3 -maxstress*A3;

ce = scal_fac*ce; ci = scal_fac*ci;

