A optimization problem with constraints

Hi, I have a optimization problem. I used the function x = fmincon(fff,x0,A,b) to do optimize ; I have some constraints on x.
Moreover, I also want to make a constraint on an intermediate variable z inside the function fff. For example let z < 0. z is in an intermediate variable of fff and will change with x.
I think fmincon cannot make a constraint on the intermediate variable z , how can I do this? Use other function instead of fmincon?

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 25 Jun. 2015

1 Stimme

function minx = minimizex
x0 = 1; %some guess
A = []; b = [];, Aeq = []; beq = []; lb = []; ub = [];
minx = fmincon(@(x) x, X0, A, b, Aeq, beq, lb, ub, @lastz);
end
function [c, ceq] = lastz(X)
timesteps = [.....] as appropriate
boundaryconditions = [....] as appropriate
zposition = 2; %which of the outputs is z?
%"x is parameter to the ode"
[T, Z] = ode45( @(t,y) YourFunction(t, y, x), timesteps, boundaryconditions);
z = Z(end,zposition);
c = z;
ceq = [];
end

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 24 Jun. 2015

1 Stimme

You'll have to use a nonlinear constraint on x, i.e. it fails if z is outside of range.

4 Kommentare

Walter Roberson
Walter Roberson am 24 Jun. 2015
However, it might not always be feasible to calculate the ranges of x that are valid and implement them all as constraints. For example if one z = sin(50*x) and wanted to constrain -0.05 <= z <= 0.05 then if x is unconstrained then it would not be feasible to create the complete list of ranges of x where the condition will hold.
craftsman
craftsman am 24 Jun. 2015
Thank you a lot for your answer. The function fff is an ode function. X is the parameter of the ode, z is the result of the ode. My objective is to minimize x under the condition z < 0. Is this means the nonlinear constraint on x is the ode function itself? The nonlinear of x the ode result with parameter x?
Matt J
Matt J am 24 Jun. 2015
Bearbeitet: Matt J am 24 Jun. 2015
The function fff is an ode function. X is the parameter of the ode, z is the result of the ode
If z is the "result of the ode" that means z is a function of time t (or some other variable). Is that correct? If so, at what times t do you want z(t)<=0 to be satisfied? If z(t)<=0 over some infinite or continuous range of t, then fmincon cannot handle that. You might have to look at fseminf.
If instead you're happy to satisfy z(t(i))<=0 at some finite set of sample times t(i), then simply return z(t(i)) from your nonlcon function.
craftsman
craftsman am 25 Jun. 2015
Thank you a lot for your answer. Yes, z is the "result of the ode" and z is a function of time. The constraint on z is z(t(end)) <= 0. So I can simply set c = z(t(end)) in my nonlcon function? Is that correct?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by