# Concave Utility Function Plot

For the last few days, I have been trying to replicate the following figure with TikZ (I am open to use pgfplots, but I have not been able to achieve much with pgfplots so far; therefore I am using TikZ).

The picture below shows the closest I have been able to get using TikZ. The code below the picture is a WME of the code I use to get the plot.

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[domain=0.01:6.5]
\draw[->] (0,0) -- (6.5,0) node[right] {$\cdot$};
\draw[->] (0,0) -- (0,6.5) node[above] {$u(\cdot)$};
\draw[densely dotted, domain=0.2:3.3] plot (\x, 2.5+\x);
\draw[thick, smooth, samples=100, yshift=4.6cm, domain=0.01:6.5] plot ({ \x, ln(\x)});
\draw[-, thin, densely dotted] (0,2.7) -- (0.15,2.7) node[left] {$u(x)$};
\draw[-, thin, densely dotted] (0,5.8) -- (3.3,5.8) node[left] {$u(y)$};
\draw[-, thin, densely dotted] (0,4.25) -- (1.75,4.25);
\draw[-, thin, densely dotted] (0.15,0) -- (0.15,2.75);
\draw[-, thin, densely dotted] (1.75,0) -- (1.75,5.15);
\draw[-, thin, densely dotted] (3.25,0) -- (3.25,5.75);
\draw[-, thin, densely dotted] (0,5.15) -- (1.75,5.15);
\end{tikzpicture}
\end{figure}

\end{document}


If possible, I would like some help in making my plot look like the one in the first picture. Though solutions with TikZ are preferred, I am open to do it with pgfplots from scratch. Can Anyone help me in achieving my goal? Thank you all!

You can actually do all the calculations within TikZ, the same syntax \coordinate (a) at (0.5,{ln(0.5)}) works to set a coordinate in some specific point of the plot, in this case, it's u(0.5).

There's only one tricky part which is the c(F,u), there it's possible to use the intersections library to brutally determine that coordinate, or do it with math. But to use math one must know that once TikZ computes a dimension it internally converts it into pt and since the plot is being handled in cm a unit conversion must be done: 1cm=28.4576pt and 1pt=0.03514cm. Now, knowing the an y (u(x)) value we can determine ist corresponding x by doing x=pow(e,y) where y must be given in cm.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[my plot/.style={
thick,
smooth,
samples=100,
domain=0.1:5},
my grid/.style={dashed,opacity=0.5, every node/.style={black,opacity=1}},
my axis/.style={latex-latex}]
\draw[my plot] (0,0) plot (\x,{ln(\x)});
\coordinate (start plot) at (0.1,{ln(0.1)}); % domain start
\coordinate (end plot) at (5,{ln(5)}); % domain end
\draw[my axis] ([shift={(-0.5cm,0.5cm)}]start plot |- end plot) node[left] {$u(\cdot)$} |- node[coordinate](origin){} ([shift={(0.5cm,-0.5cm)}]start plot -| end plot) node[below] {$\cdot$}; %creates the axis a little bigger than the plot and also sepatared
\def\x{0.5}\def\y{4}\def\p{0.55} % define the x, y and p values
\coordinate (Ux) at (\x,{ln(\x)}); % set the u(x) coordinate
\coordinate (Uy) at (\y,{ln(\y)}); % set the u(y) coordinate
\coordinate (Up) at ({\p*\x+(1-\p)*\y},{ln(\p*\x+(1-\p)*\y)}); % set the u(p*x+(1-p)*y) coordinate
\draw (Ux) -- coordinate[pos=1-\p] (Up-mid) (Uy); % set the coordinate on the linear curve
\path let \p1=(Up-mid), \n1={pow(e,\y1*0.03514)} in (28.4576*\n1,\y1) coordinate (Up-mid2); %this is the most tricky part explained in the answer
% with everything set, just draw the lines:
\draw[my grid] (Ux) |- node[below]{$x$} (origin) |- node[left]{$u(x)$} cycle;
\draw[my grid] (Uy) |- node[below]{$y$} (origin) |- node[left]{$u(y)$} cycle;
\draw[my grid] (Up) |- node[below right,font=\scriptsize]{$px+(1-p)y$} (origin) |- node[left]{$u(px+(1-p)y)$} cycle;
\draw[my grid] (Up-mid2) |- node[below,font=\scriptsize]{$c(F,u)$} (origin) |- node[left]{$pu(x)+(1-p)u(y)$} cycle;
\draw[my grid] (Up-mid) -- (Up-mid2);
\end{tikzpicture}
\end{document}