Subfunctions in optimization objective function

2 views (last 30 days)
Hi, I am trying to use the fmincon function for a minimization problem.
I am trying to minimize the total gibbs energy of the system (objective function) but the function requires calculation of activities (which are modelled by a sub function). Can we use the general framework of fmincon to compute the optimization function?
For e.g
I want to optimize n(i) to get min(G)
G = n(1)*G(1) + n(1)*R*T*log(a1) + n(2)*G(2) + n(2)*R*T*log(a2) + ...... n(i)*G(i) + n(i)*R*T*log(ai)
Here, ai is the activity given by f(ni/(n1 + n2 + .... + ni)).
Will the current framework compute the activities at each iteration to produce the optimized value? Or do I have to reframe the problem? Or is there a better way?

Accepted Answer

Matt J
Matt J on 23 Jul 2020
Edited: Matt J on 23 Jul 2020
fmincon does not know or care about the internals of your objective function code. You can do anything there, and call whatever subfunctions you wish, as long as the input/output relationship of the overall routine is that of a twice continuously differentiable function. The same with any nonlinear constraint functions you might supply.
In case it matters, though, note that fmincon will treat your unknown n(i) variables as continuous variables. You have no way of constraining the optimized n(i) to be integers, for example.
  3 Comments
Matt J
Matt J on 23 Jul 2020
Edited: Matt J on 23 Jul 2020
This statement does baffle me because the fmincon should be able to do constraint optimizations since I definitely want n(i) to be positive integers.
Those aren't the kind of constraints fmincon supports. For integer-constrained non-linear optimization, you would have to use ga(). But it might be worthwhile to first solve with fmincon without integer constraints and then provide that solution as one of the population of initial guesses to ga().
So, what you are saying is that the principal variables i.e. n(i) can be cast into other variables to be used by other sub functions in the objective function?
Yes, the only thing fmincon cares about is that it can call a function y=f(n) with a guess of the n(i) and receive back a value y to be minimized ... and that that function be twice differentiable.
Angshuman Podder
Angshuman Podder on 23 Jul 2020
Thank you so much. On a second thought, I guess the moles need not be integers but positive numbers.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!