function F = ss_init1_wk(x)
global U;global t;global P; global W;

global T;global Y;
%{
U1 = sum(Y(:,1),1)/T;
U2 = sum(Y(:,2),1)/T;
U3 = sum(Y(:,3),1)/T;
U4 = sum(Y(:,4),1)/T;
U5 = sum(Y(:,5),1)/T;
%}
U1 = mean(U(:,1),1)/1000;
U2 = mean(U(:,2),1)/1000;
U3 = mean(U(:,3),1)/1000;
U4 = mean(U(:,4),1)/1000;
U5 = mean(U(:,5),1)/1000;

d=x(5);

n =48;

wl = x(1);
wh = x(2);
pl(1,1) = exp(-exp(x(3)));
ph(1,1) = exp(-exp(x(4)));

for i=2:n
pl(i,1) = exp(-exp(x(3)+(i-1)*d));
ph(i,1) = exp(-exp(x(4)+(i-1)*d));
end

for i=1:n
dpl(i,1) = exp(-exp(x(3)+(i-1)*d))^4;
dph(i,1) = exp(-exp(x(4)+(i-1)*d))^4;
end

for i=1:n
lpl(i,1) = pl(i,1)+pl(i,1)^2+pl(i,1)^3+pl(i,1)^4;
lph(i,1) = ph(i,1)+ph(i,1)^2+ph(i,1)^3+ph(i,1)^4;
end

uhat(1,1) = wl*(1+pl(1,1)+pl(1,1)^2+pl(1,1)^3)+wh*(1+ph(1,1)+ph(1,1)^2+ph(1,1)^3);

uhat(2,1) = wl*(pl(1,1)^3)*(pl(1,1)+pl(1,1)^2+pl(1,1)^3+pl(1,1)^4)+...
            wh*(ph(1,1)^3)*(ph(1,1)+ph(1,1)^2+ph(1,1)^3+ph(1,1)^4);

for j=3:n
uhat(j,1) = wl*(pl(1,1)^3)*prod(dpl(1:j-2,1),1)*lpl(j-1,1)+...
            wh*(ph(1,1)^3)*prod(dph(1:j-2,1),1)*lph(j-1,1);
end

uhat1 = uhat(1,1);
uhat23 = sum(uhat(2:3,1),1);
uhat46 = sum(uhat(4:6,1),1);
uhat712 = sum(uhat(7:12,1),1);
uhat13 = sum(uhat(13:n,1),1);

X = [uhat1-U1;
     uhat23-U2;
     uhat46-U3;
     uhat712-U4;
     uhat13-U5];

F = 10000*(X'*X);
