I'm doing an optimization and I'm having trouble specifying vector constraints:
FindMinimum[{PortfolioVariance, {Total[WeightsVector] == 1}}, WeightsVector];
But when I add a constraint to the vector:
MV = FindMinimum[{PortfolioVariance, {Total[WeightsVector] == 1,
And@@WeightsVector[Subscript[w, {#}] > 0 & /@ Range[9]]}}, WeightsVector];
I can't get it to work. I just get my input as the output.
My goal is to restrict each item in the vector with an inequality.
Thanks!
User Bill came up with an excellent solution in the comments:
Is it possible to use this? WeightsVector = Table[ToExpression["w" <> ToString[n]], {n, 1, 5}]; FindMinimum[{PortfolioVariance, {Total[WeightsVector] == 1 && And @@ Map[# > 0 &, WeightsVector]}}, WeightsVector] – Bill yesterday
WeightsVector = Table[ToExpression["w" <> ToString[n]], {n, 1, 5}]; FindMinimum[{PortfolioVariance, {Total[WeightsVector] == 1 && And @@ Map[# > 0 &, WeightsVector]}}, WeightsVector]
Thanks Bill