Setup information
prologues:=2; beginfig(1); u:=0.025cm; pickup pencircle scaled 1;A pair is a coordinate, define the coordinates for the main graph. The names are descriptive.
pair origin,top_left,bottom_right; origin=(320u,860u); top_left=(320u,1060u); bottom_right=(580u,860u);A path is a pair of coordinates, typically designed so that you can draw a line between them. Define paths for the horizontal and vertical axis using the definitions above, then draw the graph.
path vert_axis,horiz_axis,budget_set; vert_axis=origin--top_left; draw vert_axis; horiz_axis= origin--bottom_right; draw horiz_axis;Label the axis lft means left, llft means lower left. You can also use top, lrt, urt. See the manual
label.lft(btex $y$ etex,(320u,1060u)); label.bot(btex $x$ etex,(580u,860u)); label.llft(btex $0$ etex,origin);Create the coordinates for the black budget line in the picture. The coordinate of the upper left corner of the budget line is 7/8 of the way between the origin and the top of the y axis, etc. Then label the points.
pair upper_left_budget_line,bottom_right_budget_line;
upper_left_budget_line=7/8[origin,top_left];
bottom_right_budget_line=3/4[origin,bottom_right];
draw upper_left_budget_line--bottom_right_budget_line;
label.lft(btex $W$ etex,upper_left_budget_line);
label.bot(btex ${W}\over{p}$ etex,bottom_right_budget_line);
Now I want to draw a short arrow that is perpendicular to the budget line, and label
the tip of the arrow to indicate the slope of the line. This is the tiny arrow
near the bottom right edge of the black budget line that is labelled (p,1)
pair base_point;Create a coordinate. The line between the origin and this coordinate will be rotated to make the arrow.
base_point:=(15u,0);Find the angle of the line segment running from the bottom right hand side of the black line to the top left hand side. The resulting angle will be fed into the dir command.
director:=angle(bottom_right_budget_line-upper_left_budget_line);Choose a point 7/8 of the way along the black budget line where the arrow will start.
pair anchor; anchor:= (7/8)[upper_left_budget_line,bottom_right_budget_line];create a line segment from anchor to achor plus base point, then rotate is until it is perpendicular to the black budget line, then draw it.
drawarrow anchor--anchor+base_point rotated (director+90);Label the tip of the arrow
label.rt(btex $(p,1)$ etex,anchor+base_point rotated (director+90));Choose a point halfway along the black budget line to act as a tangency point.
pair tangency,left_wing,right_wing; tangency:=(1/2)[upper_left_budget_line,bottom_right_budget_line];Draw the green indifference curve and label the tangency point. Note the dir command that forces the indifference curve to have the same slope as the budget line at the tangency point.
left_wing:=(-40u,90u);
right_wing:=(90u,-40u);
draw (tangency+left_wing)..(tangency+(2u,2u)){dir director}..(tangency+(25u,-15u))..(tangency+right_wing) withcolor green;
dotlabel.urt(btex $(x^\ast,y^\ast) $ etex,(tangency+(1u,1u)));
Complete the rectangle just to illustrate another useful method.
First add a point to use to create a vertical vector. top_right is the coordinate of the upper
right hand corner of the box. Compute it by finding the point where a horizontal line through
top_left intersects a vertical line through bottom_right
pair another_base_point,top_right; another_base_point:=(0,15u); top_right=whatever[top_left,top_left+base_point]=whatever[bottom_right,bottom_right+another_base_point];Draw in the top and right hand sides of the rectangle
draw top_left--top_right; draw bottom_right--top_right;Close the figure
endfig; end