function J = costFun(x)

global gp iaeWeights manWeights iaeTuning

% controller
gc = controller(x(1),x(2));

% Feedback loops
gey = feedback(1,gc*gp);
ged = feedback(gp*-1,gc,1);

% Output response to input and output disturbance
sys = [gey;ged];
[e,t]=step(sys,100);

iaeTuning = iae(t,e);

J = manWeights*(iaeTuning./iaeWeights);
return
