LaTeX forum ⇒ Graphics, Figures & TablesDraw Cost Function Using TikZ

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

Draw Cost Function Using TikZ

Postby europapark » Fri Sep 27, 2019 10:15 am

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.

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

Postby rais » Sat Sep 28, 2019 5:31 pm

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: 235
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Sun Sep 29, 2019 8:20 pm

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] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{intersections}
  4. \newcommand\myx{}
  5. \newcommand\myy{}
  6.  
  7. \begin{document}
  8. \begin{tikzpicture}[samples=32, >=latex]
  9. \draw[->] (0,0) -- (3.5,0) node [right] {$q$};
  10. \draw[->] (0,0) -- (0,2.5) node [above] {LRTC};
  11. % for LRTC data, I used the interesting part of a cubic function,
  12. % here 0.8x^3 -3.4x^2 +4x
  13. \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$)};
  14. \draw[->] (0,-5) -- +(3.5,0) node [right] {$q$};
  15. \draw[->] (0,-5) -- +(0,4) node [above] {LRAC, LRMC};
  16. % the LRAC data I derived from LRTC data by dividing by x
  17. % (slope of line going through (0,0) and hitting current (x,y)),
  18. % then I just added a down-shift and limited the domain, such that y does not
  19. % exceed 3 (or at least, not by much):
  20. \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$)};
  21. % this is a tricky one. To calculate the slope for a given point within the
  22. % LRMC curve, I calculated a virtual point next to x, by adding 0.1 to it
  23. % (mathematically more precise would probably be to use 2 points left and right
  24. % of the point in question), then using the same down-shift as for LRAC curve
  25. % and, again, using domain for y not to exceed 3 (by too much)
  26. %
  27. % since the slope is dy/dx, we just need a second point for each point of the
  28. % LRMC curve...
  29. % for delta x, I used 0.1 (my original plot used 32 samples from 0 to 3.2)
  30. % x2 = x + 0.1
  31. % y2 = 0.8 x2^3 - 3.4x2^2 +4x2
  32. % y2 = 0.8 (x+0.1)^3 - 3.4 (x+0.1)^2 + 4(x+0.1)
  33. % 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
  34. % y2 = 0.8 x^3 + 0.24x^2 + 0.024x + 0.001 -3-4x^2 -0.68x -0.034+4x+0.4
  35. % y2 = 0.8x^3 - 3.16x^2 +3.344x + 0.367
  36. % dy = y2 - y1 = 0.8x^3 -3.16x^2 + 3.344x + 0.367 - 0.8x^3 + 3.4x^2 - 4x
  37. % dy = 0.24 x^2 - 0.656x + 0.367
  38. % divided by 0.1 (dx):
  39. \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$)};
  40. % now, I'm looking for the intersection of LRAC and LRMC curves
  41. % (theoretically, there's a second intersection between those two curves,
  42. % but here, it's at x < 0, which is not displayed anyway)
  43. \path[name intersections={of=LRAC and LRMC}];
  44. \fill (intersection-1) circle(1pt) node[below right]{$B'\!, B''$};
  45. % and go up from here, to intersect with the LRTC curve:
  46. \draw[name path=vert1, black!30] (intersection-1) -- +(0,5);
  47. \path[name intersections={of=LRTC and vert1}];
  48. \fill (intersection-1) circle(1pt);
  49. % saving the x- and y-components of point B:
  50. \pgfgetlastxy{\myx}{\myy}
  51. % naming point B:
  52. \node[below right] at (intersection-1) {$B$};
  53. % go from B to zero:
  54. \draw[black!30] (intersection-1) -- (0,0);
  55. % construct a line through LRTC into zero with the same angle of y axis as B is off x axis:
  56. \draw[name path=constructed, red!30] (\myy, \myx) -- (0,0);
  57. % catch this line's intersections with LRTC line:
  58. \path[name intersections={of=constructed and LRTC}];
  59. % (the first intersection would be at (0,0); here, we're more interested in the
  60. % second intersection:
  61. \fill (intersection-2) circle(1pt) node[left]{$A$};
  62. % go down from this intersection point, to intersect with LRAC curve (A')
  63. % and LRMC curve (A''):
  64. \draw[name path=vert2, red!30] (intersection-2) -- +(0,-6);
  65. \path[name intersections={of=vert2 and LRAC}];
  66. \fill (intersection-1) circle(1pt) node[right]{$A'$};
  67. \path[name intersections={of=vert2 and LRMC}];
  68. \fill (intersection-1) circle(1pt) node[right]{$A''$};
  69. \end{tikzpicture}
  70. \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

Postby europapark » Mon Sep 30, 2019 9:49 am

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


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 5 guests