0
$\begingroup$

I want to solve the following problem:

For $0.5<q<1$, $q<r<1$, $0\leq n$, $0\leq n_1<=\lfloor{n/2}\rfloor$, and $n_1,n\in\mathbb{N}$

calculate $\arg max_{n_1} S(q,r,n,n_1) $ as a function of $n,q,r$, where

$$S(q,r,n,n_1)=\sum_{i=0\ldots n_1} \sum_{ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ j= 0\ldots n-2n_1\\ \text{s.t.} \frac{\log{r}}{\log{(1-r)}}i+\frac{\log{q}}{\log{(1-q)}}j > \frac{\log{r}}{\log{(1-r)}}(n_1-i)+\frac{\log{q}}{\log{(1-q)}}(n-2n_1-j)} f(i,j,q,r,n,n_1)$$

and

$$f(i,j,q,r,n,n_1)={{n_1}\choose{i}} {{n-2n_1}\choose{j}} r^i (1-r)^{n_1-i}q^j (1-q)^{n-2n_1-j} $$

Am I doing something wrong with the following code in Mathematica? It just keeps running, even if I specify a small $n$, e.g., $n=2$...


f[n1_, n_, i_, j_, r_, q_] := 
   Binomial[n1, i] Binomial[n - 2 n1, j] r^i (1 - r)^(n1 - i) 
     q^j (1 - q)^(n - 2 n1 - j)

w1[r_] := Log[r]/Log[1 - r]

w2[q_] := Log[q]/Log[1 - q]

S[q_, r_, n_, n1_] :=
  Sum[
    If[w1[r] i + w2[q] j > w1[r] (n1 - i) + w2[q](n - 2 n1 - j), 
      f[n1, n, i, j, r, q], 
      0], 
    {i, 0, n1}, {j, 0, n - 2 n1}]

Maximize[
  {S[n1, n, r, q], 
   0.5 <= q < 1 && q <= r < 1 && Element[n1, Integers] && Element[n, Integers] && 
   n >= 0 && 0 <= n1 <= Floor[n/2]}, 
  {n1}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.