Message Boards Message Boards

GROUPS:

NSolve takes too long to solve equation?

Posted 8 months ago
1663 Views
|
13 Replies
|
0 Total Likes
|

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:
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 8 months 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

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

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 8 months ago

Thanks for the explanation Gianluca! Plotting it out, it seems like the solution is in the 4th quadrant. In my model, ix and iy can't be negative numbers, I modified the code you had to include the constraints for ix and iy, and the plot turned out empty. I'm not sure if this is because I didn't put the constraint in the right area of the code, or does a positive solution just not exist for ix and iy? (and how would I be able to tell for the latter?) Thank you so much!

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 && ix >= 0 && 
         iy >= 0) /. {q -> 50, r -> 50, c -> 1/100, b -> 1/10}], ix, 
     Reals];
Plot[f[iy], {iy, -15, 20}]

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 8 months 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!

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 8 months 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!

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

Posted 8 months ago

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

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 8 months ago

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

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