I am trying to solve a constrained optimization problem with a system of transcendental equations and am running into issues with NMinimize. I have a system of equations (twoPopsVac) and a function (popRootsVac) to find the roots of these.

twoPopsVac[V1_, V2_, alpha_, S1_, S2_, R01_, R02_, N1_, N2_] := {(S1 - V1)*(1 - 
Exp[-R01*(1 - alpha)*Zinf1/N1 - R02*alpha*Zinf2/N2]) - Zinf1,
(S2 - V2)*(1 - Exp[-R02*(1 - alpha)*Zinf2/N2 - R01*alpha*Zinf1/N1]) - Zinf2}

popRootsVac[V1_, V2_, alpha_, S1_, S2_, R01_, R02_, N1_, N2_ ] := 
FindRoot[twoPopsVac[V1, V2, alpha, S1, S2, R01, R02, N1, N2], {Zinf1,
S2 - V1}, {Zinf2, S2*V1}]

I then create an objective function (finalSize) that is a function of the roots and try to use it in NMinimize.

finalSize[vac1_, vac2_] := Total[{Zinf1, Zinf2} /. popRootsVac[vac1, vac2, 0, N1*s01,
N2*s02, R01, R02, N1, N2 ]]

NMinimize[{finalSize[x, y], x + y == Vtotal && 0 <= x <= N1 && 0 <= y <= N2}, {x, y}]

Unfortunately, when I try to minimize, it seems like the attempted values of the parameters (x and y) are not being passed all the way through the equations. Any idea what is going on?

FindRoot::srect: Value 9000. -x in search specification {Zinf1,9000. -x} is not a number or array of numbers. >> ReplaceAll::reps: {FindRoot[twoPopsVac[x,y,0,9000.,9000.,3,2,10000,10000],{Zinf1,9000. -x},{Zinf2,9000. x}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

  • $\begingroup$ Yee might wanna see this... $\endgroup$ Commented Jun 11, 2013 at 14:34
  • $\begingroup$ Seems like that is the issue but changing it to finalSize[v1_?NumericQ, v2_?NumericQ] := Total[{Zinf1, Zinf2} /. popRootsVac[v1, v2, 0, N1*s01, N2*s02, R01, R02, N1, N2 ]] doesn't actually solve the issue. $\endgroup$
    – scottyaz
    Commented Jun 11, 2013 at 15:07
  • $\begingroup$ @0x4A4D, never mind. Issue was solved with ?NumericQ (a bit more upstream) after all! Thanks. Feel free to post as answer. $\endgroup$
    – scottyaz
    Commented Jun 11, 2013 at 16:21