0
$\begingroup$

Here is my code:

N1 = 1;
N2 = 1;
 X1 = N2/(1 - \[Sigma]);


   c = 1
surpluspayoff10011010 = (N1 + x + y)/((N1 + x + y) + N2)* X1 - 
   c y - (((N1 + x)/((N1 + x) + N2))*X1);
yargmax10011010 = Simplify[y /. NSolve[\!\(
\*SubscriptBox[\(\[PartialD]\), \(y\)]\((surpluspayoff10011010)\)\) ==
        0, y]][[2]];
yargmax10011010 = 
  Simplify[Piecewise[{{0, 
      Simplify@
       Reduce[{Rationalize@yargmax10011010 < 0  && 0 <= \[Sigma] < 1 && 
          ymax > 1}, x]}, {yargmax10011010, 
      Simplify@
       Reduce[{Rationalize@yargmax10011010 <= ymax && 
          0 <= \[Sigma] < 1 && ymax > 1}, x]}, {ymax, 
      Simplify@
       Reduce[{Rationalize@yargmax10011010 > ymax && 
          0 <= \[Sigma] < 1 && ymax > 1}, x]  }}]];
surpluspayoff10011010 = 
  Simplify[(N1 + yargmax10011010 + 
        x)/((N2) + (N1 + x + yargmax10011010))* X1 - 
    yargmax10011010 - (((N1 + x)/((N1 + x) + N2))*X1) ];
yargmax10011010 = 
  Simplify[Piecewise[{{0, 
      Simplify@
       Reduce[{Rationalize@surpluspayoff10011010 < 0 && 
          0 <= \[Sigma] < 1  && ymax > 1}, x]}, {yargmax10011010, 
      Simplify@
       Reduce[{Rationalize@surpluspayoff10011010 >= 0 && 
          0 <= \[Sigma] < 1 && ymax > 1}, x]}}]];

I cannot put the result here, since it will look very ugly here. But the thing is I already gave the condition for 0<\sigma<1 , 1< ymax, but the result for yargmax10011010 is something that violated these conditions. Basicly,look at the result of yargmax10011010 when y=0, we have conditions such as ymax =<1, and such

$\endgroup$
9
  • $\begingroup$ Your code is complex and somewhat messy. Perhaps you could reduce it to a simpler example. Nevertheless, I suspect that your problem ultimately is that you did not explicitly give appropriate assumptions when using Simplify. If you want to set global assumptions, so you don't have to specify them every time you run Simplify, look into $Assumptions. You may also be interested in this tutorial: Using assumptions. $\endgroup$
    – MarcoB
    Commented Sep 8, 2019 at 22:24
  • $\begingroup$ Thank you, I will try that $\endgroup$
    – user66418
    Commented Sep 8, 2019 at 22:36
  • $\begingroup$ It did not work, the result still does not make sense (basicly we have for yargmax 2 values that overlap) $\endgroup$
    – user66418
    Commented Sep 8, 2019 at 22:46
  • $\begingroup$ It doesn't appear that any of your 9 Simplify or 5 Rationalize are accomplishing anything for you. With or without those I get the result Piecewise[{{0, ymax<=1 || 2+x+Sqrt[1/(1-σ)]!=0 || σ>=1 || σ<0}, {(2+x+Sqrt[1-σ]-2*σ-x*σ)/(σ-1), 2+x+Sqrt[1/(1-σ)]>=0 && 2+x+ymax+Sqrt[1/(1-σ)]>=0 && 0<=σ<1] && ymax>1}}, ymax] $\endgroup$
    – Bill
    Commented Sep 8, 2019 at 23:14
  • $\begingroup$ Hi Bill, please look at my comment in Jack post $\endgroup$
    – user66418
    Commented Sep 8, 2019 at 23:41

1 Answer 1

0
$\begingroup$

I used simpler variable names (e.g., y1 in place of yargmax10011010) and rather than redefining them created new ones (this last because when you are tracking down a problem it often is better not to redefine variables).

I believe that MarcoB is correct, adding assumptions to Simplify removes the offending inequalities.

N1 = 1;
N2 = 1;
X1 = N2/(1 - σ);
c = 1;

s1 = (N1 + x + y)/((N1 + x + y) + N2)*X1 - 
  c y - (((N1 + x)/((N1 + x) + N2))*X1)
(* -y - (1 + x)/((2 + x) (1 - σ)) + 
 (1 + x + y)/((2 + x + y) (1 - σ)) *)

The first pass

y1 = Simplify[y /. NSolve[D[s1, y] == 0, y]][[2]]
(* (2. + x + Sqrt[1. - 1. σ] - 2. σ - 
 1. x σ)/(-1. + σ) *)

The second pass

y2 = Simplify[
  Piecewise[{
    {0, Simplify@
      Reduce[{Rationalize@y1 < 0 && 0 <= σ < 1 && ymax > 1}, 
       x]}, {y1, 
     Simplify@
      Reduce[{Rationalize@y1 <= ymax && 0 <= σ < 1 && 
         ymax > 1}, x]}, {ymax, 
     Simplify@
      Reduce[{Rationalize@y1 > ymax && 0 <= σ < 1 && ymax > 1},
        x]}}
   ], 
  ymax > 1
  ]

I will have to use a snapshot for the result

Mathematica graphics

Use y2 for new version of s1

s2 = Simplify[(N1 + y2 + x)/((N2) + (N1 + x + y2))*X1 - 
      y2 - (((N1 + x)/((N1 + x) + N2))*X1), ymax > 1]

Mathematica graphics

and finally

y3 = Simplify[
  Piecewise[{
    {0, Simplify@
      Reduce[{Rationalize@s2 < 0 && 0 <= \[Sigma] < 1 && ymax > 1}, 
       x]}, {y2, 
     Simplify@
      Reduce[{Rationalize@s2 >= 0 && 0 <= \[Sigma] < 1 && ymax > 1}, 
       x]}
    }],
  ymax > 1
  ]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ As you can see, the result makes no sense, just look at it, in the first line 2+x+square root of blah blah is always greater than 0 , and in the second line 2+x+ square root is always larger than 0 as well, so y can be both 0 and the second thing at the same time. So if 0<sigma<1, we have 2 values of y , at the same time $\endgroup$
    – user66418
    Commented Sep 8, 2019 at 23:39
  • $\begingroup$ Your question as I understood it was about violating constraints. In this example the constraints are not violated but are redundant (with ymax > 1 the second statement is not required). Did you want the redundant constraint removed? $\endgroup$ Commented Sep 8, 2019 at 23:45
  • $\begingroup$ The result is wrong, just plug in sigma equal 0.95, ymax equal 2 for example, and you see y is equal to 0. And just think about it, the function is not maximized at y=0. I used Nsolve to find max because the function is concave. But thanks anyways for your help, I think maybe I should solve this on paper, perhaps? $\endgroup$
    – user66418
    Commented Sep 8, 2019 at 23:46
  • $\begingroup$ I am not familiar with the problem and am unable to tell whether zero is wrong. Setting sigma =0.95 and ymax = 2, when I plot y1 I get a line. When I plot y2 I get a constant of 2 below -8.47214, a constant of zero above . -6.47214 and a line connecting the two between.those bounds. For 'y3' I get zero everywhere. $\endgroup$ Commented Sep 9, 2019 at 1:06
  • $\begingroup$ The first condition is true everywhere except x==6.47214 and produces zero. The second condition is true at x==6.47214 and the expression computes to be zero. $\endgroup$ Commented Sep 9, 2019 at 1:15

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.