% Object function to be minimized
% for the 6:1 HEN

function[J] = Object_61(x,par)
% Unscale variables
% x = x.*par.sc.x;

% Defining parameters
P1 = par.P1;
P2 = par.P2;
P3 = par.P3;
P4 = par.P4;
P5 = par.P5;
P6 = par.P6;
P7 = par.P7;

% Defining outlet variables
T0 = par.T0;

w1 = x(16);
w2 = x(17);

T1 = x(2);
T2 = x(3);
T3 = x(4);
T4 = x(5);
T5 = x(6);
T6 = x(7);
T7 = x(8);

% Cost function
J = -(P1*(T1-T0)*w1 + P2*(T2-T1)*w1 + P3*(T3-T2)*w1 + P4*(T4-T3)*w1 + P5*(T5-T4)*w1 + P6*(T6-T5)*w1 + P7*(T7-T0)*w2);
J = J/1000;
end