function [F] = nonlin_trussFUN(u)

global a1 a2 a3 x theta alpha E L D W1 W2

% function for performing nonlinear analysis on truss

scale = 5e-3;

u1 = u(1)/12; %converting to ft
u2 = u(2)/12;

finalt = acot((x + u1)/(L + u2));
finala = acot((D - x - u1)/(L + u2));

cosft = cos(finalt); sinft = sin(finalt);
cosfa = cos(finala); sinfa = sin(finala);

A = [cosft, sinft;
	0, 1;
	-cosfa, sinfa];

%d1 = sqrt((L+u2)^2 + (x+u1)^2) - L/sinft;
%d2 = sqrt((L+u2)^2 + u1^2) - L;
%d3 = sqrt((L+u2)^2 + (D - x - u1)^2) - L/sinfa;

d1 = sqrt((L+u2)^2 + (x+u1)^2) - sqrt(L^2 + x^2) ;
d2 = sqrt((L+u2)^2 + u1^2) - L;
d3 = sqrt((L+u2)^2 + (D - x - u1)^2) - sqrt(L^2 + (D - x)^2);
 
y = (E/L)*[d1*a1; d2*a2; d3*a3];

% Calculating the functions, equilibrium

F = A'*y - [W1; W2]; F = scale*F;