Different inputs for x0 at fmincon

6 views (last 30 days)
Romans
Romans on 3 Dec 2012
I am using a fmincon function in Matlab because I want to optmize a function with constraints.
I wrote: [x,fval] = fmincon(@time,x0,[],[],[],[],[],[],@confun);
where [t,range,W_total]=time(x0)
The problem is that the inputs that I want to send to the constraints function (confun) are not the same that I put at X0 in order to solve the function time. I would like that the parameters that I obtained as outputs of the function time (t,range,W_total) were the inputs for the constrain function.
How can I solve this problem?

Answers (2)

Walter Roberson
Walter Roberson on 3 Dec 2012
Write a little wrapper function on the constraint function that takes an x as input, calls your "time" on that x, gets the outputs, and proceeds with those values as inputs to your real constraint function.

Matt J
Matt J on 3 Dec 2012
Edited: Matt J on 3 Dec 2012
Your objective function time() and your constraint function confun() have to be written as separate functions of x, and there's no way to make fmincon derive output for both of them from a single call to a 3rd function. You could make wrappers as Walter suggests, but this still means that multiple calls to time() would be made by fmincon for the same x0, and you will have to accept that.
That said, however, there are some fancy tricks with which you can make the objective and constraint functions share certain intermediate quantities that you don't want to recompute redundantly,
Since this is a low-dimensional problem, however, and since you are a novice user (judging from your earlier posts), I don't know if it's worth starting at this level of complexity.
  12 Comments
Matt J
Matt J on 4 Dec 2012
The code you've shown doesn't answer the questions we asked you. I will repeat them:
What initial starting guess x0 did you provide? How many iterations did it run? What was the final x value returned? What other diagnostic information did fmincon print to the screen? When you run with 3 output arguments
[x,fval,exitflag,output]=fmincon(...)
what is the value of exitflag and output that gets returned?
Also, you haven't really shown the part of your code that is informative. Things you've hidden like [CALCULATIONS THAT BRINGS OUT variable t with A,S,P_i,Cl] are the part of the code that carries the real information.
Romans
Romans on 6 Dec 2012
I cannot put all my code here because it is too long, but if you give me your mail I would really appreciate it

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!