# 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: Answer
13 Replies
Sort By:
Posted 8 months ago
 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] Answer
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!  Answer
Posted 8 months ago
 Don't post code as an image. It is difficult to read or put into Mathematica. Answer
Posted 8 months ago
 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}] Answer
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}] Answer
Posted 8 months ago
 f[iy] is a ConditionalExpression. The existence condition is its last element. It seems that there are indeed positive solutions: In:= Last[f[iy]] // N f[400.] Out= iy > 338.568 Out= 0.742669 Answer
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 and Out, 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! Answer
Posted 8 months ago
 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. Answer
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! Answer
Posted 8 months ago
 Are you trying to find solutions where ix==iy? Answer
Posted 8 months ago
 Yes, I am expecting ix==iy as the nash equilibrium because this is symmetrical. Answer
Posted 8 months ago
 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] Answer
Posted 8 months ago
 Thank you so much Professor Gianluca! You've been so helpful!!! Answer