1
$\begingroup$

I am trying to solve this equation

The link has a screen capture of the equation and the solution. I am looking for the values of a1 and a2 in particular, but they need to be real numbers. s1 and s2 are integers. Now if I remove the condition of integers, then (as expected) the computation takes too long (it hadn't finished for an hour). My questions are:

  1. Is it possible to define a1 and a2 to be reals, and s1 and s2 to be integers?

  2. I would like to reduce the possible values of a1 and a2 to the tenth decimal point (i.e. between 0 and 1, it can have 0.1, 0.2, 0.3,...0.9). Can this be done in Mathematica?

Edit (The code for the equation):

Maximize[{3/100000 - (
   Subscript[s, 1]*Subscript[a, 1] + 
    Subscript[s, 2]*Subscript[a, 2])/(50000 Subscript[a, 1]) - (
   3 (Subscript[s, 1]*Subscript[a, 1] + 
      Subscript[s, 2]*Subscript[a, 2]))/(25000 Subscript[a, 2]) + 1/(
   400000000000 Subscript[a, 1] Subscript[a, 2]) + (
   3 (Subscript[s, 1]*Subscript[a, 1] + 
      Subscript[s, 2]*Subscript[a, 2])^2)/(
   100000 Subscript[a, 1] Subscript[a, 2]) + (9 Subscript[a, 1])/(
   100000 Subscript[a, 2]), 
  Subscript[a, 1] >= 1 && Subscript[a, 1] <= 5 && 
   Subscript[a, 2] >= 1 && Subscript[a, 2] <= 5 && 
   Subscript[s, 1] + Subscript[s, 2] == 10 && Subscript[s, 1] >= 0 && 
   Subscript[s, 2] >= 0}, {Subscript[a, 1], Subscript[a, 2], 
  Subscript[s, 1], Subscript[s, 2]}, Integers]
$\endgroup$
4
  • $\begingroup$ Please provide the equation as code and not an image, so that we can copy-paste it instead of typing it out. As for point 2., you could simply define b1 = 10*a1, b2 = 10*a2 and restrict b1, b2 to integers between 0 and 10. $\endgroup$ Commented Oct 30, 2015 at 6:21
  • $\begingroup$ The inequalities for a1 and a2 automatically define them as real in Mathematica. Check Element for defining symbols as Integers, etc. $\endgroup$
    – bbgodfrey
    Commented Oct 30, 2015 at 13:36
  • $\begingroup$ @MariusLadegårdMeyer, Thank you for point 2! I will try that method today. I have edited the question and copied the code for the equation. $\endgroup$
    – p1988
    Commented Oct 30, 2015 at 14:27
  • $\begingroup$ @bbgodfrey, a1 and a2 are defined as reals only if I remove the Integers specification from the equation. Otherwise, they come out to be integers always. $\endgroup$
    – p1988
    Commented Oct 30, 2015 at 14:29

1 Answer 1

2
$\begingroup$

Exact optimization with mixed real and integer variables is not yet implemented.

ClearAll[a, s]

Format[a[n_]] := Subscript[a, n];
Format[s[n_]] := Subscript[s, n];

Maximize[{3/100000 + 1/(400000000000*a[1]*
            a[2]) + (9*a[1])/
         (100000*a[2]) - 
       (a[1]*s[1] + a[2]*s[2])/
         (50000*a[1]) - 
       (3*(a[1]*s[1] + a[2]*s[2]))/
         (25000*a[2]) + 
       (3*(a[1]*s[1] + a[2]*s[2])^2)/
         (100000*a[1]*a[2]), 
     a[1] >= 1 && a[1] <= 5 && 
       a[2] >= 1 && a[2] <= 5 && 
       s[1] + s[2] == 10 && 
       s[1] >= 0 && s[2] >= 0, 
     Element[s[1] | s[2], Integers]}, 
   {a[1], a[2], s[1], s[2]}]

(*  Maximize::mixdom: Exact optimization with mixed real and integer variables is not yet implemented. >>

Maximize[{3/100000 + 1/(400000000000 Subscript[a, 1] Subscript[a, 2]) + (
   9 Subscript[a, 1])/(100000 Subscript[a, 2]) - (
   Subscript[a, 1] Subscript[s, 1] + Subscript[a, 2] Subscript[s, 2])/(
   50000 Subscript[a, 1]) - (
   3 (Subscript[a, 1] Subscript[s, 1] + Subscript[a, 2] Subscript[s, 2]))/(
   25000 Subscript[a, 2]) + (
   3 (Subscript[a, 1] Subscript[s, 1] + Subscript[a, 2] Subscript[s, 2])^2)/(
   100000 Subscript[a, 1] Subscript[a, 2]), 
  Subscript[a, 1] >= 1 && Subscript[a, 1] <= 5 && Subscript[a, 2] >= 1 && 
   Subscript[a, 2] <= 5 && Subscript[s, 1] + Subscript[s, 2] == 10 && 
   Subscript[s, 1] >= 0 && 
   Subscript[s, 2] >= 0, (Subscript[s, 1] | Subscript[s, 2]) ∈ 
   Integers}, {Subscript[a, 1], Subscript[a, 2], Subscript[s, 1], Subscript[s,
   2]}]  *)

So you must use NMaximize

NMaximize[{3/100000 + 1/(400000000000*a[1]*
            a[2]) + (9*a[1])/
         (100000*a[2]) - 
       (a[1]*s[1] + a[2]*s[2])/
         (50000*a[1]) - 
       (3*(a[1]*s[1] + a[2]*s[2]))/
         (25000*a[2]) + 
       (3*(a[1]*s[1] + a[2]*s[2])^2)/
         (100000*a[1]*a[2]), 
     a[1] >= 1 && a[1] <= 5 && 
       a[2] >= 1 && a[2] <= 5 && 
       s[1] + s[2] == 10 && 
       s[1] >= 0 && s[2] >= 0, 
     Element[s[1] | s[2], Integers]}, 
   {a[1], a[2], s[1], s[2]}]

(*  {0.00928, {Subscript[a, 1] -> 5, Subscript[a, 2] -> 1., Subscript[s, 1] -> 10,
   Subscript[s, 2] -> 0}}  *)
$\endgroup$
0

Your Answer

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

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