#Ok to post homework #Lucy Martinez, 02-13-22, Assignment 7 restart: read `C7.txt`: #-----My Old code: PureNashEqui:=proc(G) local i,j,S: S:={}: for i from 1 to nops(G) do for j from 1 to nops(G[1]) do if i in BR1(G,j) and j in BR2(G,i) then S:=S union {[i,j]}; else S:=S; fi; od: od: S: end proc: #----------------------Problem 2-----------------------# # Write a procedure TypeCounts22(K1,K2) # that inputs a very large positive integer (at least ten million, otherwise there may be some Maple issues, # the current code for MNE22(G) does not address some pathological cases, but if you make K1 large enough it # should not be a problem), and fairly large positive integer K2 (say, around 10000), # uses RG(2,2,K1) K2 times and outputs the following list of length 4 of floating-point numbers # evalf( #[Number of Games with Exactly One Pure Nash Equilibrium , # Number of Games with Exactly Two Pure Nash Equilibrium and No Mixed one , # Number of Games with No Pure Nash Equilibrium and one Mixed, # Number of Games with Two Pure and One Mixed] /K2) TypeCounts22:=proc(K1,K2) local L, G, i, P, M: L:=[0,0,0,0]: for i from 1 to K2 do G:=RG(2,2,K1): P:=PureNashEqui(G); M:=MNE22(G); if nops(P)=1 then L[1]:=L[1]+1: fi: if nops(P)=2 and nops(M)=2 then L[2]:=L[2]+1: fi: if nops(M)=1 and nops(P)=0 then L[3]:=L[3]+1: fi: if nops(M)=3 and nops(P)=2 then L[4]:=L[4]+1: fi: od: for i from 1 to 4 do L[i]:=L[i]/K2: od: evalf[5](L): end: TypeCounts22(100000000,10000); # [0.7522, 0., 0.1281, 0.1197] TypeCounts22(100000000,10000); # [0.7490, 0., 0.1201, 0.1309] TypeCounts22(100000000,10000); # [0.7498, 0., 0.1265, 0.1237] TypeCounts22(100000000,10000); # [0.7519, 0., 0.1207, 0.1274] TypeCounts22(100000000,10000); # [0.7418, 0., 0.1298, 0.1284] #----------------------Problem 5-----------------------# # Generalize procedure PayOffG(G,p1,p2) # To write a procedure PayOffGG(G,p1,p2) # where G is an arbitrary 2-person game, with say, m (=nops(G)) strategies for Player Row, # and n (=nops(G[1]) strategies for Player Column, and p1, p2, are probability vectors # (i.e. they add up to 1) and outputs a list of length 2 with the payoffs of Player Row and Player Col. # Note: You should check that they add-up to 1, and return FAIL if they don't, PayOffGG:=proc(G,p1,p2) local S1,S2,i,j,L: S1:=0: S2:=0: L:=[0,0]: for i from 1 to nops(p1) do S1:=S1+p1[i]: od: for j from 1 to nops(p2) do S2:=S2+p2[j]: od: if S1=1 and S2=1 then for i from 1 to nops(p1) do for j from 1 to nops(p2) do L[1]:=L[1]+(p1[i]*p2[j]*G[i,j,1]): L[2]:=L[2]+(p1[i]*p2[j]*G[i,j,2]): od: od: else RETURN(FAIL): fi: L: end: