### Tags: boundaries, certain, fmincon, input, limits, matlab, model, optimize, powerplant, programming, signal, theparameters, tryin, upper

# Upper and Lower Boundaries in fmincon

On Programmer » Matlab

12,280 words with 2 Comments; publish: Wed, 07 May 2008 10:43:00 GMT; (20093.75, « »)

Hi,

I am tryin to optimize an input signal to a certain Model

(Powerplant). I'd like to put limits (upper and lower) on the

parameters which I want to optimize. I hence use the to vectors that

fmincon accepts for this. the problem is the following:

I have put the lower limit on the parameters to 0.2 and upper to 1.0

(otherwise my plant cannot operate, and behaves inaccurate) despite

this fmincon "guesses" on negative values on the parameters. I find

it strange because it is not following the lower limits obviously. Is

this common or am I totally lost ?

The code for further clarification :

%%%%%%%%%%%%%%%%%%%MAIN %%%%%%%%%%%%%%%%%%%%%%%%%

clear all

global GT_var HP_stress DR_HPp extThermStress q

%REINIT TEMPERATURES T[1]-T[10]

Tmin = 520;

Tmax = 570;

NoPoints = 10;

ThermoMechStressHPT = linspace(Tmin,Tmax,NoPoints);

q=0;

% Initial value guesses for GTLoad Levels

theta0(1)= 0.44;

theta0(2)= 0.6;

theta0(3) = 0.8;

theta0(4) = 2000;

theta0(5) = 2000;

theta0(6) = 1000;

theta0(7) = 500;

GTlevels_max = 1;

dt = 50; % minimum relative time between intervals

thetamin=[0.2 0.2 0.2 dt dt dt dt];

thetamax=[GTlevels_max GTlevels_max GTlevels_max 1e6 1e6 1e6 1e6 ];

%options = optimset('TypicalX', [1 1 1 1000 1000 1000 1000],

'TolCon', 1e-6,

'TolX',1e-8,'TolFun',1e-8,'DiffMinChange',0.05,'DiffMaxChange',0.5);

options = optimset('TypicalX', [1000 1000], 'TolCon', 1e-1,

'TolX',1e-4,'TolFun',1e- 1,'DiffMinChange',4,'DiffMaxChange',400,

'MaxFunEvals',1e4);

xott=fmincon('OptimTimeJT',theta0,[],[],

[],[],thetamin,thetamax,'Optim

TimeConstT',options);

%%%%%%%%%%%%%%%%%%%%%END MAIN %%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%% NONLINEAR CONSTRAINTS %%%%%%%%%%%%%%%%%%%%%%%%

function [C,Ceq]=OptimTimeConstT(theta)

global GT_var HP_stress DR_HPp extThermStress q

v2 = min(max(theta(1),0),1.0);

v3 = min(max(theta(2),0),1.0);

v4 = min(max(theta(3),0),1.0);

t1 = max(theta(4),1)+ 0;

t2 = max(theta(5),1)+t1;

t3 = max(theta(6),1)+t2;

t4 = max(theta(7),1)+t3;

[theta(4:7)]

[theta(1:3)]

[v2 v3 v4]

q = q+1

pause(0.01);

%GTLoad Signal

GT_timein=[0 t1 t2 t3 t4]';

GT_signals=[0.2 v2 v3 v4 1.0]';

GT_var = [GT_timein GT_signals];

sim('plant2',t4)

%pause(10)

%format long

% Desired DrumPressure

DR_HPpDesire = 8.5e6;

max_slope = 8.3e-4;

DR_HPp(end);

Ceq=[];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%

% THERMAL STRESS CONSTRAINTS IN INTERVALS

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%

% Limit on the extThermalStress

%ThermStressMaxAllowed = 60e8

ThermStressMaxAllowed = 2.9e8;

Times = extThermStress.time;

size(Times);

lastTime = floor(Times(end));

Values = extThermStress.signals.values;

size(Values);

lastVal = Values(end);

FixedTime = 12000;

% first column time, second column values

newThermalStress=[lastTime+1:FixedTime;

ones(1,FixedTime-lastTime)*lastVal]';

%lastvalue and Time

externalThermalStress = [Times Values];

% Puts together the new and the old to an extended

extendedThermalStress = [externalThermalStress; newThermalStress];

extendedThermalStressValues = extendedThermalStress(:,2);

extendedThermalStressTimes = extendedThermalStress(:,1);

%Number of windows

Windows = 2;

TimeFrames = FixedTime / Windows;

ThermalStress = zeros(Windows,1);

% Intervalise

for s=1:Windows

select = (extendedThermalStressTimes >= TimeFrames*(s-1)) &

(extendedThermalStressTimes <= TimeFrames*s);

maxStress = max(extendedThermalStressValues(select))

;

if s == 1

StressBound = linterp(extendedThermalStressTimes,

extendedThermalStressValues,[TimeFrames*

s]);

elseif s==Windows

StressBound = linterp(extendedThermalStressTimes,

extendedThermalStressValues,[TimeFrames*

(s-1)]);

else

StressBound = linterp(extendedThermalStressTimes,

extendedThermalStressValues,[TimeFrames*

(s-1) TimeFrames*s]);

end

ThermalStress(s) = max(maxStress, StressBound);

end

ThermalStres

*http://matlab.todaysummary.com/q_matlab_61579.html*

All Comments

Leave a comment...

- 2 Comments
- Ok Id like to clarify further:
I know that according to the fmincon manual it is said that :

"x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub) defines a set of lower and

upper bounds on the design variables in x, so that the solution is

always in the range lb <= x <= ub."

I want no only the SOLUTION to stay in this range but the "guesses"

on the parameters at each iteration. Is this possible ?

/Hesam

Hesam Mortazavi wrote:

>

> Hi,

> I am tryin to optimize an input signal to a certain Model

> (Powerplant). I'd like to put limits (upper and lower) on the

> parameters which I want to optimize. I hence use the to vectors

> that

> fmincon accepts for this. the problem is the following:

> I have put the lower limit on the parameters to 0.2 and upper to

> 1.0

> (otherwise my plant cannot operate, and behaves inaccurate) despite

> this fmincon "guesses" on negative values on the parameters. I find

> it strange because it is not following the lower limits obviously.

> Is

> this common or am I totally lost ?

> The code for further clarification :

> %%%%%%%%%%%%%%%%%%%MAIN %%%%%%%%%%%%%%%%%%%%%%%%%

> clear all

> global GT_var HP_stress DR_HPp extThermStress q

> %REINIT TEMPERATURES T[1]-T[10]

> Tmin = 520;

> Tmax = 570;

> NoPoints = 10;

> ThermoMechStressHPT = linspace(Tmin,Tmax,NoPoints);

> q=0;

> % Initial value guesses for GTLoad Levels

> theta0(1)= 0.44;

> theta0(2)= 0.6;

> theta0(3) = 0.8;

> theta0(4) = 2000;

> theta0(5) = 2000;

> theta0(6) = 1000;

> theta0(7) = 500;

> GTlevels_max = 1;

> dt = 50; % minimum relative time between intervals

> thetamin=[0.2 0.2 0.2 dt dt dt dt];

> thetamax=[GTlevels_max GTlevels_max GTlevels_max 1e6 1e6 1e6 1e6 ];

> %options = optimset('TypicalX', [1 1 1 1000 1000 1000 1000],

> 'TolCon', 1e-6,

>

'TolX',1e-8,'TolFun',1e-8,'DiffMinChange',0.05,'DiffMaxChange',0.5);

> options = optimset('TypicalX', [1000 1000], 'TolCon', 1e-1,

> 'TolX',1e-4,'TolFun',1e- 1,'DiffMinChange',4,'DiffMaxChange',400,

> 'MaxFunEvals',1e4);

>

xott=fmincon('OptimTimeJT',theta0,[],[],

[],[],thetamin,thetamax,'Opt

> im

> TimeConstT',options);

> %%%%%%%%%%%%%%%%%%%%%END MAIN %%%%%%%%%%%%%%%%%%%%%%%%%%%%

> %%%%%% NONLINEAR CONSTRAINTS %%%%%%%%%%%%%%%%%%%%%%%%

> function [C,Ceq]=OptimTimeConstT(theta)

> global GT_var HP_stress DR_HPp extThermStress q

> v2 = min(max(theta(1),0),1.0);

> v3 = min(max(theta(2),0),1.0);

> v4 = min(max(theta(3),0),1.0);

> t1 = max(theta(4),1)+ 0;

> t2 = max(theta(5),1)+t1;

> t3 = max(theta(6),1)+t2;

> t4 = max(theta(7),1)+t3;

> [theta(4:7)]

> [theta(1:3)]

> [v2 v3 v4]

> q = q+1

> pause(0.01);

> %GTLoad Signal

> GT_timein=[0 t1 t2 t3 t4]';

> GT_signals=[0.2 v2 v3 v4 1.0]';

> GT_var = [GT_timein GT_signals];

> sim('plant2',t4)

> %pause(10)

> %format long

> % Desired DrumPressure

> DR_HPpDesire = 8.5e6;

> max_slope = 8.3e-4;

> DR_HPp(end);

> Ceq=[];

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%

> % THERMAL STRESS CONSTRAINTS IN INTERVALS

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%

> % Limit on the extThermalStress

> %ThermStressMaxAllowed = 60e8

> ThermStressMaxAllowed = 2.9e8;

> Times = extThermStress.time;

> size(Times);

> lastTime = floor(Times(end));

> Values = extThermStress.signals.values;

> size(Values);

> lastVal = Values(end);

> FixedTime = 12000;

> % first column time, second column values

> newThermalStress=[lastTime+1:FixedTime;

> ones(1,FixedTime-lastTime)*lastVal]';

> %lastvalue and Time

> externalThermalStress = [Times Values];

> % Puts together the new and the old to an extended

> extendedThermalStress = [externalThermalStress; newThermalStress];

> extendedThermalStressValues = extendedThermalStress(:,2);

> extendedThermalStressTimes = extendedThermalStress(:,1);

> %Number of windows

> Windows = 2;

> TimeFrames = FixedTime / Windows;

> ThermalStress = zeros(Windows,1);

> % Intervalise

> for s=1:Windows

> select = (extendedThermalStressTimes >= TimeFrames*(s-1)) &

> (extendedThermalStressTimes <= TimeFrames*s);

> maxStress = max(extendedThermalStressValues(select))

;

> if s == 1

> StressBound = linterp(extendedThermalStressTimes,

> extendedThermalStressValues,[TimeFrames*

s]);

> elseif s==Windows

> StressBound = linterp(extendedThermalStressTimes,

> extendedThermalStressValues,[TimeFrames*

(s-1)]);

> else

> StressBound = linterp(extendedThermalStressTimes,

> extendedThermalStressValues,[TimeFrames*

(s-1) TimeFrames*s]);

> end

>

> ThermalStress(s) = max(maxStress, StressBound);

> end

> ThermalStres

#1; Wed, 07 May 2008 10:44:00 GMT

- Ok Id like to clarify further:
- In article <ef2b127.-1.matlab.todaysummary.com.webx.raydaftYaTP>, "Hesam Mortazavi" <hesam_mortazavi
.matlab.todaysummary.com.hotmail.com> wrote:

> Hi,

> I am tryin to optimize an input signal to a certain Model

> (Powerplant). I'd like to put limits (upper and lower) on the

> parameters which I want to optimize. I hence use the to vectors that

> fmincon accepts for this. the problem is the following:

> I have put the lower limit on the parameters to 0.2 and upper to 1.0

> (otherwise my plant cannot operate, and behaves inaccurate) despite

> this fmincon "guesses" on negative values on the parameters. I find

> it strange because it is not following the lower limits obviously. Is

> this common or am I totally lost ?

> The code for further clarification :

> %%%%%%%%%%%%%%%%%%%MAIN %%%%%%%%%%%%%%%%%%%%%%%%%

> clear all

> global GT_var HP_stress DR_HPp extThermStress q

> %REINIT TEMPERATURES T[1]-T[10]

> Tmin = 520;

> Tmax = 570;

> NoPoints = 10;

> ThermoMechStressHPT = linspace(Tmin,Tmax,NoPoints);

> q=0;

> % Initial value guesses for GTLoad Levels

> theta0(1)= 0.44;

> theta0(2)= 0.6;

> theta0(3) = 0.8;

> theta0(4) = 2000;

> theta0(5) = 2000;

> theta0(6) = 1000;

> theta0(7) = 500;

> GTlevels_max = 1;

> dt = 50; % minimum relative time between intervals

> thetamin=[0.2 0.2 0.2 dt dt dt dt];

> thetamax=[GTlevels_max GTlevels_max GTlevels_max 1e6 1e6 1e6 1e6 ];

> %options = optimset('TypicalX', [1 1 1 1000 1000 1000 1000],

I'll guess this is a scale problem. You have three parameters

that are on the order of 1, whereas the others are as large

as 1e6. TolCon is set at 1e-6. Since its a vector constraint,

it can slop over on those small parameters. Fix this by

taking the log of those last 4 parameters, then restore by

exponentiating inside your objective function.

Now all parameters are the same order of magnitude. This will

make your entire problem behave better anyway.

HTH,

John D'Errico

The best material model of a cat is another, or preferably the same, cat.

A. Rosenblueth, Philosophy of Science, 1945

Those who can't laugh at themselves leave the job to others.

Anonymous

#2; Wed, 07 May 2008 10:45:00 GMT

- In article <ef2b127.-1.matlab.todaysummary.com.webx.raydaftYaTP>, "Hesam Mortazavi" <hesam_mortazavi