5
$\begingroup$

I am trying to reduce a function in two variables($n_1$ and $n_2$) whose domain is the set of Integers. I get a long list of pairs of values for these two variables(instead of a range). This could be because the range of $n_2$ changes for each $n_1$. I just want the maximum value of $n_1$ and $n_2$. Can you please guide me?

 driftParamSet = 1.9 - 0.2 Subscript[n, 2] + Subscript[n, 1] (-0.2 + (2.91434*10^-16 Subscript[n, 1])/(1. Subscript[n, 1] + 1.5 Subscript[n, 2])); driftγ = 17; Reduce[driftParamSet> -driftγ && Subscript[n, 1]>= 0 && Subscript[n, 2]>= 0,{Subscript[n, 1],Subscript[n, 2]}, Integers]; 

Current output: $n_1=0\land n_2=1\left\|n_1=0\land n_2=2\right\|n_1=0\land n_2=3\|n_1=0\land n_2=4 \\......\\\left\|n_1=0\land n_2=90\right\|n_1=0\land n_2=91\|\\.....\\ \left(n_1=92\land n_2=2\right)\lor \left(n_1=93\land n_2=0\right)\lor \left(n_1=93\land n_2=1\right)\lor \left(n_1=94\land n_2=0\right)$

Expected output:

$n_1$=94 and $n_2=$91

$\endgroup$
2
  • 1
    $\begingroup$ Several symbols in your code are undefined. Please provide the definitions to aid the reader in answering your question. $\endgroup$ Commented Mar 7, 2019 at 1:52
  • $\begingroup$ @bbgodfrey, sorry about that. I have updated the question now. $\endgroup$ Commented Mar 7, 2019 at 1:58

2 Answers 2

5
$\begingroup$

Let the large result of Reduce be rs. Then the maximum of each quantity is determined by

Max@Cases[rs, Equal[Subscript[n, 1], z_] -> z, Infinity] (* 94 *) Max@Cases[rs, Equal[Subscript[n, 2], z_] -> z, Infinity] (* 94 *) 

not 91 as speculated in the question. The corresponding terms in rs can be obtained by

Position[rs, 94, Infinity] (* {{94, 2, 2}, {4559, 1, 2}} *) rs[[94]] (* Subscript[n, 1] == 0 && Subscript[n, 2] == 94 *) rs[[4559]] (* Subscript[n, 1] == 94 && Subscript[n, 2] == 0 *) 
$\endgroup$
5
  • $\begingroup$ thank you! To understand this better, the Cases[] function with the specified parameter creates a list of values of n1/n2 and the Max[] function operates on this list to give the maximum? $\endgroup$ Commented Mar 7, 2019 at 2:21
  • 1
    $\begingroup$ @gaganso Precisely so. $\endgroup$ Commented Mar 7, 2019 at 2:22
  • $\begingroup$ @bbgodrey, the equation has changed slightly and have patterns of the form 19167.<=Subscript[n, 2]<=19486.. I tried to use LessThanEqual in place of Equal with necessary changes but it doesn't seem to work. Should I ask a new question or update this? $\endgroup$ Commented Mar 28, 2019 at 1:43
  • 1
    $\begingroup$ @gaganso I recommend asking a new question. No one will notice a small change to an existing question. In your new question, cite this question and explain how the new question differs. $\endgroup$ Commented Mar 28, 2019 at 2:00
  • $\begingroup$ I have created a new question here - mathematica.stackexchange.com/questions/194075/… $\endgroup$ Commented Mar 28, 2019 at 2:12
4
$\begingroup$

An alternative is to use Solve after Rationalizeing input expressions:

driftParamSet = Rationalize[1.9 - 0.2 n2 + n1 (-0.2 + (2.91434*10^-16 n1)/(1. n1 + 1.5 n2)), 10^-16] driftγ = 17; solutions = Solve[driftParamSet > -driftγ && n1 >= 0 && n2 >= 0, {n1, n2}, Integers]; Max /@ Transpose[{n1, n2} /. solutions] 

{94, 94}

Yet another approach is using ArgMax:

Extract[ArgMax[{#, driftParamSet > -driftγ && n1 >= 0 && n2 >= 0}, {n1, n2}, Integers]& /@ {n1, n2}, {{1, 1}, {-1, -1}}] 

{94, 94}

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.