Message Boards Message Boards

NSolve takes too long to solve equation?

Posted 3 years ago

Hi All, I have an equation that can't be evaluated, and I'm not sure what is causing it. Even if I try and let it run overnight, the evaluation is still running the next day. The equation that I'm trying to solve for is at the very bottom of all my mathematica script (I tried a few variations, all had to be aborted). I wasn't sure how to just add in the equation without the rest of the notebook, and I thought the other workings in the notebook might be useful to give context.

Just to give context. I have two players, X and Y, with two welfare functions, funx and funy. The variables are a1x, a1y, a2x, a2y, ix and iy. I also have some undefined parameters b, q, r, and c. It's a two period game, so player X chooses a1x and ix in the first round, then a2x in the second round. Similar for player Y. Using backwards induction, I was able to figure out what a2x and a2y would be in terms of ix and iy, and subbed them back into the welfare functions, then I also found a1x and a1y in terms of the parameters. However, when I have the welfare functions in terms of just ix and iy, and differentiate funx with respect to ix and try to solve for zero, thats when Solve or Reduce no longer works. Looking at the original welfare functions funx and funy, it's clear that ix and iy do make things more complex, but not to the point of making this unsolvable right? Figuring out ix and iy are the last step to figuring out the nash equilibrium for this game theoretic model, so i would really appreciate help in figuring out how to solve for them! Thanks in advance!

Attachments:
POSTED BY: Sabrina Chui
13 Replies

This variation gives a quick answer:

Solve[Simplify[(-r + 
      9/40 b ((7 Sqrt[c] Sqrt[r] + Sqrt[q + b iy q + 49 c r])^2/(1 + 
           b ix)^2 + (2 q^2)/(
         Sqrt[q + b ix q + 
           49 c r] (-14 Sqrt[c] Sqrt[r] + Sqrt[q + b ix q + 49 c r] + 
            Sqrt[q + b iy q + 49 c r]))) == 0) /. {q -> 50, r -> 50, 
    c -> 1/100, b -> 1/10}], ix, Reals]
POSTED BY: Gianluca Gorni
Posted 3 years ago

Hi Gianluca, thanks for giving an alternative way of doing it. I entered that and got this whole blob. I'm not quite sure what kind of "answer" this means. Is this a real number? or is it now a complex number? I'm still new to mathematica so when the output looks like this I'm a bit confused. Thank you!

enter image description here

POSTED BY: Sabrina Chui

It is a way of representing algebraic numbers in terms of the normalized equation they solve. In this case the equation is of degree 16 in the dummy variable #1, with coefficients that are themselves polynomials in iy. The Root object can be used as any other algebraic expression. There is also a validity condition on iy. For example you can plot ix as a function of iy this way:

f[iy_] = ix /. 
   First@Solve[
     Simplify[(-r + 
          9/40 b ((7 Sqrt[c] Sqrt[r] + 
                 Sqrt[q + b iy q + 49 c r])^2/(1 + 
                 b ix)^2 + (2 q^2)/(Sqrt[
                 q + b ix q + 49 c r] (-14 Sqrt[c] Sqrt[r] + 
                  Sqrt[q + b ix q + 49 c r] + 
                  Sqrt[q + b iy q + 49 c r]))) == 0) /. {q -> 50, 
        r -> 50, c -> 1/100, b -> 1/10}], ix, Reals];
Plot[f[iy], {iy, -15, -9}]
POSTED BY: Gianluca Gorni
Posted 3 years ago
POSTED BY: Sabrina Chui

Don't post code as an image. It is difficult to read or put into Mathematica.

POSTED BY: Moderation Team

f[iy] is a ConditionalExpression. The existence condition is its last element. It seems that there are indeed positive solutions:

In[36]:= Last[f[iy]] // N
f[400.]

Out[36]= iy > 338.568

Out[37]= 0.742669
POSTED BY: Gianluca Gorni
Posted 3 years ago

Thank you Gianluca, if you don't mind me asking more questions, which part of the code is parsing out the positive solutions? What is the purpose of the f[400.]? And I'm a little confused by Out[36] and Out[37], does this mean the solution is that iy > 338.568 AND/OR iy = 0.742669? Are these the only two positive solutions? Once again, thank you so much!

POSTED BY: Sabrina Chui

Your code ix >= 0 && iy >= 0 makes Solve accept only the solutions in the first quadrant. The existence condition is iy > 338.568. I chose a simple number larger than that, iy=400, and f[400.] is the corresponding value of ix.

POSTED BY: Gianluca Gorni
Posted 3 years ago

Thanks Professor Gianluca, I tried to replicate these same steps to do the opposite to plot iy as a function of ix, but how would I then combine them? I'm trying to figure out the nash equilibrium solution for iy and ix, and in easier example, I'd normally be plotting iy as a function of ix, and ix as a function of iy and seeing where they cross, but since they're not showing up in the plot, how would I figure how where these functions intersect?

Thank you again!

POSTED BY: Updating Name

Are you trying to find solutions where ix==iy?

POSTED BY: Gianluca Gorni
Posted 3 years ago

Yes, I am expecting ix==iy as the nash equilibrium because this is symmetrical.

POSTED BY: Sabrina Chui

Then you can simply write the condition into your system:

Solve[Simplify[{(-r + 
       9/40 b ((7 Sqrt[c] Sqrt[r] + Sqrt[q + b iy q + 49 c r])^2/(1 + 
              b ix)^2 + (2 q^2)/(Sqrt[
              q + b ix q + 49 c r] (-14 Sqrt[c] Sqrt[r] + 
               Sqrt[q + b ix q + 49 c r] + 
               Sqrt[q + b iy q + 49 c r]))) == 0), ix == iy, 
    ix > 0} /. {q -> 50, r -> 50, c -> 1/100, b -> 1}], {ix, 
  iy}, Reals]
POSTED BY: Gianluca Gorni
Posted 3 years ago

Thank you so much Professor Gianluca! You've been so helpful!!!

POSTED BY: Sabrina Chui
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract