Graphics, Figures & TablesDraw Cost Function Using TikZ

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
europapark
Posts: 2
Joined: Fri Sep 27, 2019 10:08 am

Draw Cost Function Using TikZ

Post by europapark »

Hi!

I would like to draw this cost function using TikZ:

https://www.tankonyvtar.hu/en/tartalom/ ... /07-03.png

There are a few economics graphs in this package, but not the cost function, unfortunately: http://static.latexstudio.net/wp-conten ... papp01.pdf

I am new to TikZ. Any help is very appreciated.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Draw Cost Function Using TikZ

Post by rais »

Perhaps you could start with the LRTC curve. Then you can post some code, where you could ask for how to derive the LRAC/LRMC curves from.
And, of, course, you could explain what those acronyms stand for. I'd say long run total/average/marginal cost, but `I'm leaning far out the window' here, as one of our sayings go.

KR
Rainer
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Draw Cost Function Using TikZ

Post by rais »

Well, I crunched some numbers---this is what I came up with (provided, the actual data for LRTC curve is not relevant):

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\newcommand\myx{}
\newcommand\myy{}

\begin{document}
\begin{tikzpicture}[samples=32, >=latex]
\draw[->] (0,0) -- (3.5,0) node [right] {$q$};
\draw[->] (0,0) -- (0,2.5) node [above] {LRTC};
% for LRTC data, I used the interesting part of a cubic function,
% here 0.8x^3 -3.4x^2 +4x
\draw[name path=LRTC, color=green, thick, domain=0:3] plot (\x, {0.8*\x*\x*\x-3.4*\x*\x+4*\x}) node[right]{LRTC($q$)};
\draw[->] (0,-5) -- +(3.5,0) node [right] {$q$};
\draw[->] (0,-5) -- +(0,4) node [above] {LRAC, LRMC};
% the LRAC data I derived from LRTC data by dividing by x
% (slope of line going through (0,0) and hitting current (x,y)),
% then I just added a down-shift and limited the domain, such that y does not
% exceed 3 (or at least, not by much):
\draw[name path=LRAC, color=green, thick, domain=0.3:3.9, yshift=-4cm] plot (\x, {0.8*\x*\x-3.4*\x+4}) node[right]{LRAC($q$)};
% this is a tricky one. To calculate the slope for a given point within the
% LRMC curve, I calculated a virtual point next to x, by adding 0.1 to it
% (mathematically more precise would probably be to use 2 points left and right
% of the point in question), then using the same down-shift as for LRAC curve
% and, again, using domain for y not to exceed 3 (by too much)
%
% since the slope is dy/dx, we just need a second point for each point of the
% LRMC curve...
% for delta x, I used 0.1 (my original plot used 32 samples from 0 to 3.2)
% x2 = x + 0.1
% y2 = 0.8 x2^3 - 3.4x2^2 +4x2
% y2 = 0.8 (x+0.1)^3 - 3.4 (x+0.1)^2 + 4(x+0.1)
% y2 = 0.8 (x^3 + 3 x^2 0.1 +3 x 0.1^2 + 0.1^3) -3.4(x^2+2x0.1+0.1^2) +4x + 0.4
% y2 = 0.8 x^3 + 0.24x^2 + 0.024x + 0.001 -3-4x^2 -0.68x -0.034+4x+0.4
% y2 = 0.8x^3 - 3.16x^2 +3.344x + 0.367
% dy = y2 - y1 = 0.8x^3 -3.16x^2 + 3.344x + 0.367 - 0.8x^3 + 3.4x^2 - 4x
% dy = 0.24 x^2 - 0.656x + 0.367
% divided by 0.1 (dx):
\draw[name path=LRMC, color=blue!60!red, thick, domain=0.1:2.5, yshift=-4cm] plot (\x, {2.4*\x*\x-6.56*\x+3.67}) node[right] {LRMC($q$)};
% now, I'm looking for the intersection of LRAC and LRMC curves
% (theoretically, there's a second intersection between those two curves,
% but here, it's at x < 0, which is not displayed anyway)
\path[name intersections={of=LRAC and LRMC}];
\fill (intersection-1) circle(1pt) node[below right]{$B'\!, B''$};
% and go up from here, to intersect with the LRTC curve:
\draw[name path=vert1, black!30] (intersection-1) -- +(0,5);
\path[name intersections={of=LRTC and vert1}];
\fill (intersection-1) circle(1pt);
% saving the x- and y-components of point B:
\pgfgetlastxy{\myx}{\myy}
% naming point B:
\node[below right] at (intersection-1) {$B$};
% go from B to zero:
\draw[black!30] (intersection-1) -- (0,0);
% construct a line through LRTC into zero with the same angle of y axis as B is off x axis:
\draw[name path=constructed, red!30] (\myy, \myx) -- (0,0);
% catch this line's intersections with LRTC line:
\path[name intersections={of=constructed and LRTC}];
% (the first intersection would be at (0,0); here, we're more interested in the
% second intersection:
\fill (intersection-2) circle(1pt) node[left]{$A$};
% go down from this intersection point, to intersect with LRAC curve (A')
% and LRMC curve (A''):
\draw[name path=vert2, red!30] (intersection-2) -- +(0,-6);
\path[name intersections={of=vert2 and LRAC}];
\fill (intersection-1) circle(1pt) node[right]{$A'$};
\path[name intersections={of=vert2 and LRMC}];
\fill (intersection-1) circle(1pt) node[right]{$A''$};
\end{tikzpicture}
\end{document}
Of course, I have no way of knowing if my assumptions are correct or flawed by a coincidence or two, trying to get some sense out of the picture you posted. And I may have confused LRAC with LRMC...

KR
Rainer
europapark
Posts: 2
Joined: Fri Sep 27, 2019 10:08 am

Draw Cost Function Using TikZ

Post by europapark »

WOW! :o Incredible job, thank you very much! I can take it from here.
Post Reply