⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reactcurvesnash.m

📁 一个用MATLAB编写的优化控制工具箱
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Example to illustrate reaction curves, infinite games, and % Nash equilibria.%% Author: K. Passino% Version: 2/5/02%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear all% Define payoff (cost) functions for each playertheta1=-4:0.05:4; % Ok, while we think of it as an infinite game computationally	              % we of course only study a finite number of points.m=length(theta1);theta2=-5:0.05:5;n=length(theta2);% A set of cost functions, J1 for player 1 and J2 for player 2for ii=1:length(theta1)	for jj=1:length(theta2)		J1(ii,jj)=-1*(exp( (-(theta1(ii)-2)^2)/8  + ((-(theta2(jj)-4)^2)/2))); 		J2(ii,jj)=-1*(exp( (-(theta1(ii)-1)^2)/1  + ((-(theta2(jj)+1)^2)/6)));	endend% Next, compute the reaction curves for each player and will plot on top of J1 and J2for j=1:length(theta2)	[temp,t1]=min(J1(:,j)); % Find the min point on J1 with theta2 fixed, for all theta2	R1(j)=theta1(t1); % Compute the theta1 value that is the best reaction to each theta2endfor i=1:length(theta1)	[temp,t2]=min(J2(i,:)); % Find the min point on J2 with theta1 fixed	R2(i)=theta2(t2); % Compute the theta2 value that is the best reaction to each theta1endfigure(1)clfsubplot(121)contour(theta2,theta1,J1,10)hold oncontour(theta2,theta1,J2,10)hold onplot(theta2,R1,'k-')hold onplot(R2,theta1,'k--')xlabel('\theta^2')ylabel('\theta^1')title('(a) J_1, J_2, reaction curves R_1 (-) and R_2 (--)')hold off% Compute the Nash equilibria (with the view that it is a bimatrix game):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			theta1(i)			j			theta2(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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Another possible set of cost functions:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for ii=1:length(theta1)	for jj=1:length(theta2)		J1(ii,jj)=-2*(exp( (-(theta1(ii)-2)^2)/5 +(-4*(theta1(ii)*theta2(jj))/20) + ((-(theta2(jj)-3)^2)/2))); 		J2(ii,jj)=-1*(exp( (-(theta1(ii)-1)^2)/4 + (5*(theta1(ii)*theta2(jj))/10) + ((-(theta2(jj)+1)^2)/2)));	endend% Next, compute the reaction curves for each player and will plot on top of J1 and J2for j=1:length(theta2)	[temp,t1]=min(J1(:,j)); % Find the min point on J1 with theta2 fixed, for all theta2	R1(j)=theta1(t1); % Compute the theta1 value that is the best reaction to each theta2endfor i=1:length(theta1)	[temp,t2]=min(J2(i,:)); % Find the min point on J2 with theta1 fixed	R2(i)=theta2(t2); % Compute the theta2 value that is the best reaction to each theta1endfigure(1)subplot(122)contour(theta2,theta1,J1,10)hold oncontour(theta2,theta1,J2,10)hold onplot(theta2,R1,'k-')hold onplot(R2,theta1,'k--')xlabel('\theta^2')ylabel('\theta^1')title('(b) J_1, J_2, reaction curves R_1 (-) and R_2 (--)')hold off% Compute the Nash equilibria (with the view that it is a bimatrix game):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			theta1(i)			j			theta2(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')endfigure(2)clfcontour(theta2,theta1,J1,10)hold oncontour(theta2,theta1,J2,10)hold onplot(theta2,R1,'k-')hold onplot(R2,theta1,'k--')xlabel('\theta^2')ylabel('\theta^1')title('J_1, J_2, R_1 (-), R_2 (--), and iteration trajectory')hold off%-------------------------------------% End of program%-------------------------------------

⌨️ 快捷键说明

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