# Optimisation Problem

• Apr 26th 2010, 11:28 AM
rem88
Optimisation Problem
Hi,

I have a optimasation problem where i want to minimise a function (A) which has a number of varibales (T) and a number of these are constarined.

I was wondering what code i use to do this, because fmincon only minimises T to find A.

T is a matrix of 10 values in a 1 x 10 by matrix and i want to constrain some values so some values of T are greater or less than others and 4 of them are fixed.

Id appreciate any help

Rem
• Apr 28th 2010, 12:55 AM
CaptainBlack
Quote:

Originally Posted by rem88
Hi,

I have a optimasation problem where i want to minimise a function (A) which has a number of varibales (T) and a number of these are constarined.

I was wondering what code i use to do this, because fmincon only minimises T to find A.

T is a matrix of 10 values in a 1 x 10 by matrix and i want to constrain some values so some values of T are greater or less than others and 4 of them are fixed.

Id appreciate any help

Rem

Function Reference (Optimization Toolbox™)

http://www.mathworks.com/access/help...g/fmincon.html

CB
• Apr 28th 2010, 02:27 AM
rem88
Hi,

This is what i tried, but instead of minimising A by changing T, the values of T are minimised to find the initial guess of A.

Here is the function to be minimised

%Question 4 - Optimum Heat Exchanger Area

function A = MinArea(T,A)

T0 =[373.15; 400; 500; 773.15; 873.15; 600; 673.15; 700; 573.15; 800]

T =[373.15; 1; 1; 773.15; 873.15; 1; 673.15; 1; 573.15; 1]

T1 = T(1);
T2 = T(2);
T3 = T(3);
T4 = T(4);
T5 = T(5);
T6 = T(6);
T7 = T(7);
T8 = T(8);
T9 = T(9);
T10 = T(10);

mCp = 4200;
% W/C

AT1 = T2-T1
AT1a = T9-T10

AT2 = T3-T2;
AT2a = T7-T8;

AT3 = T4-T3;
AT3a = T5-T6;

Q1 = mCp*AT1;
Q2 = mCp*AT2;
Q3 = mCp*AT3;

AMTD1 = ((T9+T10)./2)-((T1+T2)./2);
AMTD2 = ((T7+T8)./2)-((T2+T3)./2);
AMTD3 = ((T5+T6)./2)-((T3+T4)./2);

U1 = 1000;
% W/m^2.K
U2 = 800; % W/m^2.K
U3 = 400; % W/m^2.K

A1 = Q1./(U1*AMTD1);
A2 = Q2./(U2*AMTD2);
A3 = Q3./(U3*AMTD3);

A = A1 + A2 + A3

And this is another m file i run to solve it

lb(1) = 373.15;
lb(4) = 773.15;
lb(5) = 873.15;
lb(7) = 673.15;
lb(9) = 573.15;

ub(1) = 373.15;
ub(4) = 773.15;
ub(5) = 873.15;
ub(7) = 673.15;
ub(9) = 573.15;

a=[1 -1 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 1 -1;0 0 1 0 0 0 -1 0 0 0;0 0 0 0 0 0 1 -1 0 0;0 1 -1 0 0 0 0 0 0 0;0 0 1 0 0 -1 0 0 0 0;0 0 1 -1 0 0 0 0 0 0;0 0 0 0 -1 1 0 0 0 0;]
b=[0;0;0;0;0;0;0;0]

aeq = [1 -1 0 0 0 0 0 0 1 -1;0 1 -1 0 0 0 1 -1 0 0;0 0 1 -1 1 -1 0 0 0 0;1 0 0 -1 1 -1 1 -1 1 -1;1 0 0 0 0 0 0 0 0 0;0 0 0 1 0 0 0 0 0 0;0 0 0 0 1 0 0 0 0 0;0 0 0 0 0 0 1 0 0 0;0 0 0 0 0 0 0 0 1 0]

beq = [0;0;0;0;373.15;773.15;873.15;673.15;573.15]

T0 =[373.15; 400; 500; 773.15; 873.15; 600; 673.15; 700; 573.15; 800]

[T,Aval] = fmincon(@MinArea,T0,a,b,aeq,beq,lb,ub)

• Apr 28th 2010, 02:58 AM
CaptainBlack
Quote:

Originally Posted by rem88
Hi,

This is what i tried, but instead of minimising A by changing T, the values of T are minimised to find the initial guess of A.

Here is the function to be minimised

%Question 4 - Optimum Heat Exchanger Area

function A = MinArea(T,A)

T0 =[373.15; 400; 500; 773.15; 873.15; 600; 673.15; 700;

Why is A an argument of MinArea?

CB
• Apr 28th 2010, 11:10 AM
rem88
Yeah, your right the A shouldn't be there.

I have been working on it today, but I cant get the correct answer (which i know from solving in excel). Matlab only carries out 2 iterations.

If i put the initial guess for T near to the final values, then the answer is correct. If the initial Ts are different then the answer is different

Is there a way to increase the iterations?
--------------------------------------------------------------
function A = MinArea(T)

T1 = T(1);
T2 = T(2);
T3 = T(3);
T4 = T(4);
T5 = T(5);

mCp = 4200;
% W/C

AT1 = T1-373.15;
AT1a = 573.15-T5;

AT2 = T2-T1;
AT2a = 673.15-T4;

AT3 = 773.15-T2;
AT3a = 873.15-T3;

Q1 = mCp*AT1;
Q2 = mCp*AT2;
Q3 = mCp*AT3;

AMTD1 = ((573.15+T5)./2)-((373.15+T1)./2);
AMTD2 = ((673.15+T4)./2)-((T1+T2)./2);
AMTD3 = ((873.15+T3)./2)-((T2+773.15)./2);

U1 = 1000;
% W/m^2.K
U2 = 800; % W/m^2.K
U3 = 400; % W/m^2.K

A1 = Q1./(U1*AMTD1);
A2 = Q2./(U2*AMTD2);
A3 = Q3./(U3*AMTD3);

A = A1 + A2 + A3
--------------------------------------------------------------

function [c,ceq] = equal(T);

ceq = [373.15+573.15-T(1)-T(5);T(1)-T(2)+673.15-T(4);T(2)-773.15+873.15-T(3)];
c=[];
--------------------------------------------------------------

a=[1 0 0 0 0;0 0 0 0 1;1 -1 0 0 0;0 0 0 1 0;0 1 0 0 0;0 1 -1 0 0]

b=[573.15;573.15;0;673.15;773.15;0]

aeq = [1 0 0 0 1;1 -1 0 -1 0;0 1 -1 0 0;0 0 0 0 0]

beq = [373.15+573.15;-673.15;+773.15-873.15;0]

options.MaxFunEval = Inf;
options.MaxIter = Inf;
options.TolFun = Inf;
options.TolCon = Inf;
options.MinIter = Inf;
options = optimset(
'LargeScale','on');

[T,Aval,exitflag,output] = fmincon(@MinArea,[441;565;665;549;504],a,b,aeq,beq,[],[],@equal,options)
--------------------------------------------------------------

Rem
• Apr 29th 2010, 12:52 AM
elbarto
Quote:

Originally Posted by rem88
Yeah, your right the A shouldn't be there.
options.MaxFunEval = Inf;
options.MaxIter = Inf;
options.TolFun = Inf;
options.TolCon = Inf;

options.MinIter = Inf;
options = optimset(
'LargeScale','on');

I am not sure if this is correct or not. I would suspect that after 1 iteration the routine will exit based on the TolFun being solved to a value less the Inf (try setting to [] to invoke matlab default value of 1e-6 i think). Can you post the command line output? I will try run the code when I have access to MATLAB next.

Elbarto
• Apr 29th 2010, 05:31 AM
rem88
Hi,

I just put all three in a seperate m file, in the same directory then ran this m-file

a=[1 0 0 0 0;0 0 0 0 1;1 -1 0 0 0;0 0 0 1 0;0 1 0 0 0;0 1 -1 0 0]

b=[573.15;573.15;0;673.15;773.15;0]

aeq = [1 0 0 0 1;1 -1 0 -1 0;0 1 -1 0 0;0 0 0 0 0]

beq = [373.15+573.15;-673.15;+773.15-873.15;0]

options.MaxFunEval = Inf;
options.MaxIter = Inf;
options.TolFun = Inf;
options.TolCon = Inf;
options.MinIter = Inf;
options = optimset('LargeScale','on'
);

[T,Aval,exitflag,output] = fmincon(@MinArea,[441;565;665;549;504],a,b,aeq,beq,[],[],@equal,options)

Rem
• Apr 30th 2010, 04:08 PM
elbarto
What happened when you run that code? If you post any errors you got that appeared at the command line that would help debug your code.
• May 1st 2010, 06:41 AM
rem88
When i run it i get this

options =
MaxFunEval: []
MaxIter: []
TolFun: []
TolCon: []
iterations: 100
cgiterations: 100
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 274
In running at 18

Then a some values generated for the fucntion A.

Then this:

A =
31.1799
Optimization terminated: first-order optimality measure less than options.TolFun
and maximum constraint violation is less than options.TolCon.
No active inequalities.
T =
399.0818
524.0901
624.0901
548.1418
547.2182

Aval =
31.1799

exitflag =
1

output =
iterations: 2
funcCount: 18
stepsize: 1
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 1.0101e-009
cgiterations: []
message: [1x143 char]