3
$\begingroup$

If I try to minimize with constraints a function of several variables, with Gamma regularized function involved in the constraints it seems to works, as shown below (this is just a dummy example problem to try), where S, A , β and m are constants previously declared and assigned a value:

    Minimize[-Log[v] - Log[y] - Log[z], 
 Gamma[m, S*A*400^β*m*v^(1/m)]/Gamma[m] + 
    Gamma[m, S*A*400^β*m*z^(1/m)]/Gamma[m] + 
    Gamma[m, S*A*400^β*m*y^(1/m)]/Gamma[m] <= 1 && v <= 0.1 && 
  v >= 0.001 && z <= 0.1 && z >= 0.001 && y <= 0.1 && y >= 0.001, {v, 
  y, z}]
    {6.90776, {v -> 0.1, y -> 0.1, z -> 0.1}}

Now, since I need later to solve a problem with hundreds of variables, I try the same problem with an array of variables, but it does not work:

 Minimize[{\!\(
\*UnderoverscriptBox[\(∑\), \(i = 1\), \(3\)]\(-Log[h[i]]\)\), 
  Join[{\!\(
\*UnderoverscriptBox[\(∑\), \(i = 1\), \(3\)]\(GammaRegularized[
        1, S*A*
\*SuperscriptBox[\(400\), \(β\)]*m*h[i]]\)\) <= 
      1}, {Table[h[i] <= 0.1, {i, 3}] /. 
      List -> And} , {Table[h[i] >= 0.001, {i, 3}] /. 
      List -> And}] /. List -> And}, Table[h[i], {i, 3}]]

Minimize[{-Log[h[1]] - Log[h[2]] - Log[h[3]], 
  E^(-123.319 h[1.]) + E^(-123.319 h[2.]) + E^(-123.319 h[3.]) <= 1 &&
    h[1] <= 0.1 && h[2] <= 0.1 && h[3] <= 0.1 && h[1] >= 0.001 && 
   h[2] >= 0.001 && h[3] >= 0.001}, {h[1], h[2], h[3]}]

After trying several options, it seems that if I rewrite the problem using only variables h[i], instead of the expression in the argument to the GammarRegularizedfunction it works again (see below):

Minimize[{\!\(
\*UnderoverscriptBox[\(∑\), \(i = 1\), \(3\)]\(-Log[
\*FractionBox[\(h[i]\), \(S*A*
\*SuperscriptBox[\(400\), \(β\)]*m\)]]\)\), Join[{\!\(
\*UnderoverscriptBox[\(∑\), \(i = 1\), \(3\)]\(GammaRegularized[
        1, h[i]]\)\) <= 
      1}, {Table[h[i] <= S*A*400^β*m*0.1, {i, 3}] /. 
      List -> And} , {Table[
       h[i] >= S*A*400^β*m*0.001, {i, 3}] /. List -> And}] /. 
   List -> And}, Table[h[i], {i, 3}]]

{6.90776, {h[1] -> 12.3319, h[2] -> 12.3319, h[3] -> 12.3319}}

Why is it that I cannot use a expression as argument? I would need to pass expressions in my real problem as argument.

$\endgroup$
2
  • $\begingroup$ What values of S, A , \[Beta] and m are you using? $\endgroup$
    – bbgodfrey
    May 7, 2015 at 1:35
  • $\begingroup$ (*Parameters*) S = 10^-9.2 cl = 3*10^8 f = 5.9*10^9 w = cl/f A = (4*\[Pi]/w)^(2/1) \[Beta] = 2.5 m = 1 $\endgroup$
    – vega
    May 7, 2015 at 8:24

1 Answer 1

2
$\begingroup$

Mathematica does not like your h[i]s.

If you introduce

 shrt[head_, 
       indices_] := 
     ToExpression[StringJoin[
         ToString /@ Flatten[
             {head, 
               indices}]]]

so that e.g. shrt[h,1] becomes h1 or shrt[h,{i,j}] hij

Then this works:

S = 10^-9.2;
cl = 3*10^8 ;
f = 5.9*10^9;
w = cl/f ;
A = (4*π/w)^(2/1);
β = 2.5 ;
m = 1 ;

Join[{Sum[
   GammaRegularized[1, S*A*400^β*m*shrt[h, i]] , {i, 
    3}] <= 
        1}, {Table[shrt[h, i] <= 0.1, {i, 3}] /. 
        List -> And} , {Table[shrt[h, i] >= 0.001, {i, 3}] /. 
        List -> And}] /. List -> And}, Table[shrt[h, i], {i, 3}]]

(* {6.90776,{h1->0.1,h2->0.1,h3->0.1}} *)

$\endgroup$
2
  • $\begingroup$ Thanks. From the documentation reference.wolfram.com/language/ref/Array.html I thought you can create an array of variables just doing vars=Array[h,3] but it seems you have to convert them to symbols before somehow. In fact, ToExpression /@vars complains that h[1] is not a string or a box.. I find it odd that you cannot create an array of symbols directly, or can you? $\endgroup$
    – vega
    May 7, 2015 at 15:33
  • $\begingroup$ you can do something like ToExpression["h" <> ToString[#]] & /@ Range[5] $\endgroup$
    – chris
    May 7, 2015 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.