#OK to post #Kayla Gibson, 01/28/2022, Assignment 3 #1 Sample of Garvan Exercises # Differential Equations: f:='f': y:=f(x): dy:=diff(y,x): ddy:=diff(dy,x): dsolve(ddy+dy-12*y - sin(x)*exp(-4*x),y); # f(x) = exp(3*x)*_C2 + exp(-4*x)*_C1 + ((7*cos(x) - sin(x))*exp(-4*x))/50 # Practiced some plotting in maple #Linear Algebra: with(LinearAlgebra): f:=(i,j)->x^(i*j): A:=Matrix(4,4,f); # A:= [x x^2 x^3 x^4] # [x^2 x^4 x^6 x^8] # [x^3 x^6 x^9 x^12] # [x^4 x^8 x^12 x^16] d:=Determinant(A); # d:= x^30 - 3x^29 + x^28 + 4x^27 - 2x^26 - 2x^25 - 2x^24 + 4x^23 + x^22 - 3x^21 + x^20 factor(d); # = x^20*(x^2 + x + 1)*(x + 1)^2*(x - 1)^6 #2 Read and understand C3.txt #3 Finding outcomes of dynamical games where Row or Column goes first (by hand) G1 := RandDisGame(4, 4): G2 := RandDisGame(5, 7): print(Matrix(G1)): print(Matrix(G2)): # G1:= [8,10] [9,11] [6,15] [1,16] # [5,13] [10,14] [16,12] [4,5] # [14,9] [15,4] [11,1] [2,8] # [13,2] [7,7] [12,3] [3,6] # G2:= [9,16] [21,19] [14,13] [24,32] [25,10] [17,5] [7,12] # [30,35] [2,23] [34,28] [19,3] [8,17] [4,8] [23,14] # [3,24] [29,6] [18,18] [12,34] [20,9] [1,30] [27,2] # [5,33] [31,31] [16,20] [13,11] [15,25] [6,1] [10,7] # [28,27] [22,26] [11,21] [32,29] [26,15] [35,4] [33,22] #(a) Using G1: # (i) find the outcome of the sequential version of G1 when Player Row goes first # Option 1: Row chooses strategy R1, Column responds with strategy C4 for an outcome of 1-16 # Option 2: Row chooses strategy R2, Column responds with strategy C2 for an outcome of 10-14 # Option 3: Row chooses strategy R3, Column responds with strategy C1 for an outcome of 14-9 # Option 4: Row chooses strategy R4, Column responds with strategy C2 for an outcome of 7-7 # So Row chooses strategy R3 which maximizes Row's points, and row wins with strategy [3,1] and outcome [14,9] # (ii) find the outcome of the sequential version of G1 when Player Column goes first # Option 1: Column chooses strategy C1, Row responds with strategy R3 for an outcome of 14-9 # Option 2: Column chooses strategy C2, Row responds with strategy R3 for an outcome of 15-4 # Option 3: Column chooses strategy C3, Row responds with strategy R2 for an outcome of 16-12 # Option 4: Column chooses strategy C4, Row responds with strategy R2 for an outcome of 4-5 # So Column chooses strategy C3 which maximizes Column's points, but row wins with strategy [2,3] and outcome [16,12] # (iii) find the set of Nash Equilibria # Column 4 is dominated by Column 1, so we can eliminate it # G1-> [8,10] [9,11] [6,15] # [5,13] [10,14] [16,12] # [14,9] [15,4] [11,1] # [13,2] [7,7] [12,3] # Row 1 is dominated by Row 3, so we may eliminate it # G1-> [5,13] [10,14] [16,12] # [14,9] [15,4] [11,1] # [13,2] [7,7] [12,3] # Column 3 is dominated by Column 2, so we may eliminate it # G1-> [5,13] [10,14] # [14,9] [15,4] # [13,2] [7,7] # Both Row 1 and Row 3 are dominated by Row 2, so we may eliminate them # G1-> [14,9] [15,4] # Finally, we are left with our Nash Equilibrium [3,1] with outcome [14,9] #(b) Using G2: # (i) find the outcome of the sequential version of G1 when Player Row goes first # (ii) find the outcome of the sequential version of G1 when Player Column goes first # (iii) find the set of Nash Equilibria #4 Write a procedure AllGames(a,b) # AllGames takes as input two positive integers a and b and outputs the set of all (a*b)!^2 possible # games where Player Row has a strategies, Player Column has b strategies, each player's payoffs are # distinct and drawn from {1,...,a*b} with(combinat): AllGames := proc(a, b) local L, f, Games, i, j, k, m, n: L := permute(b*a): Games := {seq(seq([seq([seq([L[i][n + b*(m - 1)], L[j][n + b*(m - 1)]], n = 1 .. b)], m = 1 .. a)], i = 1 .. (b*a)!), j = 1 .. (b*a)!)}; end: #5 Write a procedure FullStat(a,b) # FullStat takes as input positive integers a and b (not too big) and outputs the following list: # [Number of games with No Nash Equilibria, Number of Games with One Nash Equilibria, # Number of Games with Two Nash Equilibria, Number of Games where the Row Player was better off playing second, # Number of Games where the Column was better off playing second, Number of Games where DynRC(G)=DynCR(G)] FullStat := proc(a, b) local Games, i, numNoNash, numOneNash, numTwoNash, numRowBetterSecond, numColBetterSecond, numSameOutcome, Nash, G, DynRC, DynCR, RC, CR: Games := AllGames(a, b): numNoNash := 0: numOneNash := 0: numTwoNash := 0: numRowBetterSecond := 0: numColBetterSecond := 0: numSameOutcome := 0: for i to ((b*a)!)^2 do G := Games[i]: Nash := nops(PureNashEqui(G)): RC := DynRC(G): CR := DynCR(G): if Nash = 0 then numNoNash = numNoNash + 1: elif Nash = 1 then numOneNash := numOneNash + 1: elif Nash = 2 then numTwoNash = numTwoNash + 1: fi: if RC[2][1] < CR[2][1] then numRowBetterSecond = numRowBetterSecond + 1: fi: if CR[2][2] < RC[2][2] then numColBetterSecond := numColBetterSecond + 1: fi: if RC = CR then numSameOutcome := numSameOutcome + 1: fi: od: RETURN([numNoNash, numOneNash, numTwoNash, numRowBetterSecond, numColBetterSecond, numSameOutcome]); end: # (i) What is FullStat(2,2) FullStat(2,2); # = [0, 432, 0, 0, 72, 420] # (ii) What is FullStat(3,2) FullStat(3,2); # = [0, 345600, 0, 0, 83952, 331560] # I am having issues here, I should definitely not have this many 0's #6 Write a procedure SampleStat(a,b,K) # SampleStat takes as input integers a and b, and a fairly large positive integer K, and generates K random # games where Tow has a strategies and Col has b strategies and outputs the following list of numbers (in floating-point) # evalf([(Number of Games with No Nash Equilibria)/K, (Number of Games with One Nash Equilibria)/K, # (Number of Games where the Row Player was better off playing second)/K, # (Number of Games where the Column Player was better off playing second)/K, (Number of Games where DynRC(G)=DynCR(G))/K]): SampleStat:=proc(a,b,K) local L,i,j,numNoNash, numOneNash,numTwoNash, numRowBetterSecond, numColBetterSecond, numSameOutcome,Nash, G,RC,CR: Games := [seq(RandDisGame(a, b), i = 1 .. K)]: numNoNash := 0: numOneNash := 0: numTwoNash := 0: numRowBetterSecond := 0: numColBetterSecond := 0: numSameOutcome := 0: for j to nops(Games) do G := Games[j]: Nash := nops(PureNashEqui(G)): RC := DynRC(G): CR := DynCR(G): if Nash = 0 then numNoNash = numNoNash + 1: elif Nash = 1 then numOneNash := numOneNash + 1: elif Nash = 2 then numTwoNash = numTwoNash + 1: fi: if RC[2][1] < CR[2][1] then numRowBetterSecond = numRowBetterSecond + 1: fi: if CR[2][2] < RC[2][2] then numColBetterSecond := numColBetterSecond + 1: fi: if RC = CR then numSameOutcome := numSameOutcome + 1: fi: od: RETURN([evalf(numNoNash/K), evalf(numOneNash/K), evalf(numTwoNash/K), evalf(numRowBetterSecond/K), evalf(numColBetterSecond/K), evalf(numSameOutcome/K)]); end: # Run SampleStat(10,10,10000) 5 times #1 #2 #3 #4 #5 ############################################################################################################################## #C3.txt: Maple Code for Lecture 2 of Math640 (Spring 2022) with(combinat): Help3:=proc(): print(`RandDisGame(a,b), BR1d(G,a2), BR2d(G,a1), BR1dv(G), BR2dv(G), DynRC(G), DynCR(G) `):end: #RandDisGame(a,b): A random game where Player Row has a strategies R1, R2, ..., Ra; and Player Col. has b strategies: C1, C2, ..., Cb and all pay-offs are DISCTINCT #and consist of the set {1,2,...,ab}. Try: #RandDisGame(4,6); RandDisGame:=proc(a,b) local pi1,pi2,i1,j1: pi1:=randperm(a*b): pi2:=randperm(a*b): [seq([seq([pi1[b*i1+j1],pi2[b*i1+j1]],j1=1..b)],i1=0..a-1)]: end: #G:=Rand2PlayerGame(10,20,100)[1] #BR1d(G,a2): Inputs a bi-matrix of a 2-player game G and a member a2 of A2 outputs the SUBSET of A1 that consists of the best response BR1d:=proc(G,a2) local a1: max[index]([seq(G[a1][a2][1],a1=1..nops(G))]): end: #BR2d(G,a1): Inputs a bimatrix of a game G and a member a1 of A1 outputs the SUBSET of A2 that consists of the best response BR2d:=proc(G,a1) local a2: max[index]([seq(G[a1][a2][2],a2=1..nops(G[a1]))]): end: #BR1dv(G): Inputs a bimatrix of a game G, outputs The list of size A2 with all the set of best responses # BR1dv:=proc(G) local a2: [seq(BR1d(G,a2),a2=1..nops(G[1]))]:end: #BR2dv(G): Inputs a bimatrix of a game G, outputs The list of size A1 with all the set of best responses BR2dv:=proc(G) local a1: [seq(BR2d(G,a1),a1=1..nops(G))]:end: #DynRC(G): The outcome of the Dynamical version of the game G if row goes first and Column goes next DynRC:=proc(G) local L,i,iBest, jBest: #L is the list of size A1 where L[i] is the best response of Player Column to Strategy i and Row gets G[i][L[i]][1] L:=BR2dv(G): iBest:=max[index]([seq(G[i][L[i]][1],i=1..nops(G))]): jBest:=L[iBest]: [iBest,jBest], G[iBest][jBest]: end: #DynCR(G): The outcome of the Dynamical version of the game G if Col goes first and Row goes next DynCR:=proc(G) local L,j,iBest, jBest: #L is the list of size A2 where L[j] is the best response of Player Row to Strategy j and Col gets G[L[j]][j]][2] L:=BR1dv(G): jBest:=max[index]([seq(G[L[j]][j][2],j=1..nops(L))]): iBest:=L[jBest]: [iBest,jBest], G[iBest][jBest]: end: