#OK to post #Rebecca Embar, 2-4-2022, Homework 5 read `hw2RebeccaEmbar.txt`: read `hw3RebeccaEmbar.txt`: read `C5.txt`: #1 #Payoff for player 1 payoff_1 := proc(p1,p2): return (a-p1-b*p2)*(p1-c): end: #Payoff for player 2 payoff_2 := proc(p1,p2): return (a-p2-b*p1)*(p2-c): end: #The best response functions are #BR1(p2)=(1/2)*(a+b*p2+c) #BR2(p1)=(1/2)*(a+b*p1+c) #Nash equilibria is p1 = p2 = (a+c)/(2-b) #2 G := RG(30,30,10000): PureNashEqui(G); #{[4,25]} BestTot(G); #{[4,25]},19661 BetterForBoth(G,4,25); #Empty set G := RG(30,30,10000): PureNashEqui(G); #{[30,23]} BestTot(G); #{[30,23]},19816 BetterForBoth(G,30,23); #Empty set G := RG(30,30,10000): PureNashEqui(G); #Empty set BestTot(G); #{[29,7]},19310 #3 BeatNE := proc(a,b) local games,l,i: games := AllGames(a,b): l := {}: for i from 1 to nops(games) do if nops(PureNashEqui(games[i])) = 1 and not nops(BetterForBoth(games[i],PureNashEqui(games[i])[1][1],PureNashEqui(games[i])[1][2])) = 0 then l := l union {games[i]}: fi: od: return l: end: #{[[[1, 1], [3, 2]], [[4, 3], [2, 4]]], [[[1, 1], [3, 4]], [[2, 3], [4, 2]]], [[[1, 2], [3, 4]], [[2, 3], [4, 1]]], [[[1, 3], [3, 4]], [[2, 2], [4, 1]]], [[[1, 4], [3, 3]], [[2, 2], [4, 1]]], [[[1, 4], [4, 3]], [[2, 2], [3, 1]]], [[[1, 4], [4, 3]], [[3, 2], [2, 1]]], [[[2, 1], [3, 2]], [[4, 3], [1, 4]]], [[[2, 2], [3, 1]], [[1, 4], [4, 3]]], [[[2, 2], [4, 1]], [[1, 3], [3, 4]]], [[[2, 2], [4, 1]], [[1, 4], [3, 3]]], [[[2, 3], [4, 1]], [[1, 2], [3, 4]]], [[[2, 3], [4, 2]], [[1, 1], [3, 4]]], [[[2, 4], [4, 3]], [[3, 2], [1, 1]]], [[[3, 1], [2, 2]], [[4, 3], [1, 4]]], [[[3, 2], [1, 1]], [[2, 4], [4, 3]]], [[[3, 2], [2, 1]], [[1, 4], [4, 3]]], [[[3, 3], [1, 4]], [[4, 1], [2, 2]]], [[[3, 4], [1, 1]], [[4, 2], [2, 3]]], [[[3, 4], [1, 2]], [[4, 1], [2, 3]]], [[[3, 4], [1, 3]], [[4, 1], [2, 2]]], [[[4, 1], [2, 2]], [[3, 3], [1, 4]]], [[[4, 1], [2, 2]], [[3, 4], [1, 3]]], [[[4, 1], [2, 3]], [[3, 4], [1, 2]]], [[[4, 2], [2, 3]], [[3, 4], [1, 1]]], [[[4, 3], [1, 4]], [[2, 1], [3, 2]]], [[[4, 3], [1, 4]], [[3, 1], [2, 2]]], [[[4, 3], [2, 4]], [[1, 1], [3, 2]]]} #BeatNE(2,3) took too long #4 EstBeatNE := proc(a,b,K,M) local onenash,bettertot,betterboth,i,G: onenash := 0: bettertot := 0: betterboth := 0: for i from 1 to M do G := RG(a,b,K): if nops(PureNashEqui(G)) = 1 then onenash := onenash + 1: if not member(PureNashEqui(G)[1],BestTot(G)[1]) then bettertot := bettertot + 1: fi: if nops(BetterForBoth(G,PureNashEqui(G)[1][1],PureNashEqui(G)[1][2])) > 0 then betterboth := betterboth + 1: fi: fi: od: return evalf([onenash/M,bettertot/M,betterboth/M]): end: #Resuts from EstBeatNE(10,10,1000,1000) #[0.4320000000, 0.2230000000, 0.09800000000] #[0.3930000000, 0.1910000000, 0.1000000000] #[0.4150000000, 0.2100000000, 0.1030000000] #[0.4170000000, 0.2250000000, 0.1090000000] #[0.4240000000, 0.2160000000, 0.09700000000] #5 u1 := q1*(1-q1-q2)^(d1); u2 := q2*(1-q1-q2)^(d2); diff(u1,q1); q1opt := solve(%=0,q1); diff(u2,q2); q2opt := solve(%=0,q2); solve({q1=q1opt,q2=q2opt},{q1,q2}); #NE is q1 = d2/(d1*d2+d1+d2), q2 = d1/(d1*d2+d1+d2)