nashequilibria.m

来自「一个用MATLAB编写的优化控制工具箱」· M 代码 · 共 67 行

M
67
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Example to illustrate computation of Nash equilibria of% finite two player nonzero sum "bimatrix" games. If you run% the program multiple times, with the J1 and J2 definition lines % appropriately commented out below, you can see cases where there are% zero, one, or more than one Nash equilibrium.  Now, the program% provides one example where there are two Nash solutions.%% Author: K. Passino% Version: 2/2/02%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear all% Set the number of different possible values of the decision variablesm=5; % If change will need to modify specific J1, J2 value chosen belown=3; % Set the payoff matrices J1(i,j) and J2(i,j):%J1=round(10*rand(m,n)-5*ones(m,n)) % Make it random integers between -5 and +5%J2=round(10*rand(m,n)-5*ones(m,n)) % Make it random integers between -5 and +5% One set of payoff matrices that gives two Nash equilibria:J1 =[-1     5    -3;    -2     5     1;     4     3    -2;    -5    -1     5;     3     0     2]J2 =[-1     2    -3;     2    -3     1;    -2     3     1;    -1     1    -1;     4    -4     1]% Compute the Nash equilibria:flag=0; % Flag for saying if there is no Nash equilibriafor i=1:m	    for j=1:n			if J1(i,j)<=min(J1(:,j)) & J2(i,j)<=min(J2(i,:)), % Conduct two inequality tests			display('Nash equilibrium and outcome:') % If satisfied, then diplay solution			i			j			J1(i,j) 			J2(i,j)			flag=1; % Indicates that there was one Nash equilibrium (or more)		end    endendif flag==0	display('There were no Nash equilibria')end%-------------------------------------% End of program%-------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?