- extract data from contour function
- use polyxpoly to find intersection segments
How can I color the region bounded by two level curves of countour plots?
8 views (last 30 days)
Show older comments
Hello! I think mine is a question about how the function surfc() works. I have very recently discovered to my surprise an easy way to create the Edgeworth Box of microeconomics using surfc. Here is an example (with green curves and red curves the countours of two superimposed surc() plots that ar ereoirented so you see just the contours (with colors of the two surfaces turned off).
Is there a way I can color the region bounded by one red countour and one green contour (the "eye" of a region in the Edgeworth Box)? I presume this is done with patch() but how does one identify the patch region using the contour curves?
My MatLab code follows below. Thank you in advance!
function Edgeworth_Box_Variable_Cobb_Douglas(alpha,beta)
% This function plots an Edgeworth Box for two agents with
% Cobb-Douglas utility functions.
%
% Inputs are
% alpha = the exponent of Agent 1's (Betty's) Cobb-Doulgas utility
% function
% u1(X1,Y1) = (X1^alpha)*(Y1^(1-alpha))
% beta = the exponent of Agent 2's (Alf's) Cobb-Doulgas utility
% function
% u2(X1,Y1) = (X1^beta)*(Y1^(1-beta))
%
% This block of code computes and plots the countours that are the
% indifference curves for Agent 1 and Agent 2.
[X1,Y1]=meshgrid(0:0.01:1,0:0.01:1) ;
[X2,Y2]=meshgrid(1:-0.01:0,1:-0.01:0) ;
Z1 = (X1.^alpha).*(Y1.^(1-alpha)) ;
Z2 = (X2.^beta).*(Y2.^(1-beta)) ;
hold on
axis square
view(3)
view([0,90])
sbetty = surfc(X1,Y1,Z1) ;
sbetty(1).FaceColor = 'none' ;
%sbetty(1).FaceColor = 'cyan' ;
%sbetty(1).EdgeColor = 'blue' ;
sbetty(1).EdgeColor = 'none' ;
sbetty(2).EdgeColor = 'green' ;
sbetty(2).LineWidth = 1 ;
sbetty(2).LevelStep = 1/10 ;
salf = surfc(X1,Y1,Z2) ;
salf(1).FaceColor = 'none' ;
%salf(1).FaceColor = 'yellow' ;
%salf(1).EdgeColor = 'magenta' ;
salf(1).EdgeColor = 'none' ;
salf(2).EdgeColor = 'red' ;
salf(2).LineWidth = 1 ;
salf(2).LevelStep = 1/10 ;
%This next block of code plots the contrcat curve.
x = 0:0.01:1 ;
y = (1-alpha)*beta*x./((1-beta)*alpha + (beta-alpha)*x) ;
plot(x,y,'-b','LineWidth',2.0)
% This next block of code plots a boundary around the Edgeworth Box.
plot([0 1],[0,0],'-k','LineWidth',1)
plot([0 0],[0,1],'-k','LineWidth',1)
plot([1 1],[0,1],'-k','LineWidth',1)
plot([0 1],[1,1],'-k','LineWidth',1)
hold off
end
0 Comments
Accepted Answer
darova
on 5 Jul 2020
4 Comments
More Answers (0)
See Also
Categories
Find more on Geographic Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!