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

Code, edit and compile here:
\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,
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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