# Trying to maximize an expression with integer and real variables

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]

• 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. – Marius Ladegård Meyer Oct 30 '15 at 6:21
• The inequalities for a1 and a2 automatically define them as real in Mathematica. Check Element for defining symbols as Integers, etc. – bbgodfrey Oct 30 '15 at 13:36
• @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. – p1988 Oct 30 '15 at 14:27
• @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. – p1988 Oct 30 '15 at 14:29

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

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

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