# Subfunctions in optimization objective function

1 Ansicht (letzte 30 Tage)
Angshuman Podder am 22 Jul. 2020
Bearbeitet: Matt J am 23 Jul. 2020
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?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Matt J am 23 Jul. 2020
Bearbeitet: Matt J am 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 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Matt J am 23 Jul. 2020
Bearbeitet: Matt J am 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 am 23 Jul. 2020
Thank you so much. On a second thought, I guess the moles need not be integers but positive numbers.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by