0

I am trying to use tikz to sketch these graphs but it looks irregular and don't know how to go about it. I can do almost everything with the exception of the irregular graph in red which I would need help with. Any help would be very much appreciated.Thank you.

enter image description here

\documentclass{article}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes, decorations, shadows}  
\usetikzlibrary{decorations.pathmorphing}  
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{chains,arrows,positioning,decorations.pathreplacing}  
\usetikzlibrary{fadings}  
\usetikzlibrary{patterns}  
\usetikzlibrary{calc,fit}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=15cm,compat=1.5,height=9.5cm,
axis y line=center,
axis x line=middle,
xmin=-5,xmax=5,
ymin=-5,ymax=5,
xlabel=$x$,ylabel=$y$,
anchor=center
]
%\addplot[smooth,very thick,mark size=1.5pt,color=red,mark=*] plot coordinates 
{(0,0) (1,-1) (4,-2)}; % node[right] {$y=\sqrt{x}$};

\addplot+[-latex', >=latex,color=red,smooth,very 
thick,mark=none,samples=200,unbounded coords=jump] {sqrt(x)};
\end{axis}
\end{tikzpicture}

\end{document}
4
  • Please, show to us, what you do so far. Your code will be easy to complete with missing curve.
    – Zarko
    Jun 26 '16 at 23:31
  • I reformat your MWE and correct spelling error in it. However in it is missing, as can I see, package pgfplots (I didn't add it, since your MWE is in contradiction with your question). Now it is not very clear, what is your problem. Your function? If for it you don't know math function, you can determine it with coordinates and draw smooth curve through points. is this your problem?
    – Zarko
    Jun 26 '16 at 23:55
  • Thanks but I only wanted how I could plot the red graph in the picture using one of my old code for \sqrt{x} graph. Please help.
    – user28251
    Jun 27 '16 at 0:14
  • See, if my answer fit to your wishes. Let me note: i don't understand what you mean with irregular graph, so I use two ordinary function and draw their graphs in selected domain.
    – Zarko
    Jun 27 '16 at 2:07
3

Unfortunately the question is not very clear to me, so this answer is based on guessing and provided desired images. This means, that your MWE wasn't very helpful. From it I only see, that you expect figure drawn by pgfplots and not by pure tikz ...

See, if my result is what you after:

enter image description here

Above images is done by the following code:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{width=6cm, compat=1.13,
                 title style={at={(0.5,-0.1)}, anchor=north, font=\large},
                 xlabel style = {anchor=west},
                 ylabel style = {anchor=south},
                 clip=false
                  }% <-- common styles 
    \usetikzlibrary{arrows}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[%small,anchor=aninnernode.center,
axis y line=center,
axis x line=middle,
%
xmin=-0.5,xmax=5,
ymin=-0.5,ymax=5,
xtick={0}, ytick={0},% this disables the standard
ylabel=$y$,
xlabel=$x$,
title = {$f$ is increasing},
]
\addplot[line width=2pt,red,%
         domain=0.5:4.5, samples=9, mark=none,
         ->] {0.2*(x^2) + 1};
\node[right] at (4.5,{0.2*(4.5^2) + 1})  {$f(x)$};
%
\draw[dashed]   (0,{0.2*(2^2) + 1}) node[left] {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{0.2*(3^2) + 1}) node[left] {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
\end{axis}
    \end{tikzpicture}
\hfill
    \begin{tikzpicture}
\begin{axis}[%small,anchor=aninnernode.center,
axis y line=center,
axis x line=middle,
%
xmin=-0.5,xmax=5,
ymin=-0.5,ymax=5,
xtick={0}, ytick={0},% this disables the standard
ylabel=$y$,
xlabel=$x$,
title = {$f$ is decreasing},
]
\addplot[line width=2pt,red,%
         domain=0.5:4.5, samples=9, mark=none,
         ->] {7-3*sqrt(x)};
\node[right] at (4.5,{7-3*sqrt(4.5)})  {$f(x)$};
%
\draw[dashed]   (0,{7-3*sqrt(2)})   node[left] {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{7-3*sqrt(3)})   node[left] {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
\end{axis}
    \end{tikzpicture}
\end{document}

The code is (almost) semi-explanatory, but if you have some question about it, pleas ask.

Addendum: The code for pure TikZ solution seems to be slightly simpler:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[domain=0.5:4.5, samples=17,]
% axes                        
\draw[->] (-0.5,0) -- node[below=5mm] {$f$ is increasing}
                      + (5.5,0) node[right] {$x$};
\draw[->] (0,-0.5) -- + (0,5.5) node[above] {$y$};
% graph
\draw[line width=2pt, draw=red, ->] 
    plot (\x,{0.2*(\x^2) + 1}) node[right] {$f(x)$};
%
\draw[dashed]   (0,{0.2*(2^2) + 1}) node[left]  {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{0.2*(3^2) + 1}) node[left]  {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
    \end{tikzpicture}
\hfill
    \begin{tikzpicture}[domain=0.5:4.5, samples=17]
% axes
\draw[->] (-0.5,0) -- node[below=5mm] {$f$ id decreasing}
                      + (5.5,0) node[right] {$x$};
\draw[->] (0,-0.5) -- + (0,5.5) node[above] {$y$};
% graph
\draw[line width=2pt, draw=red, ->] 
    plot (\x,{7-3*sqrt(\x)}) node[right]  {$f(x)$};
%
\draw[dashed]   (0,{7-3*sqrt(2)})   node[left] {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{7-3*sqrt(3)})   node[left] {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
    \end{tikzpicture}
\end{document}

Result of above MWE is (almost) the same as at the first solution (with use of pgfplots)

3
  • actually morning :-) ...please, get me more information about my answer. provide it what you looking for? as i already noted, i have problems to understand what is your problem. For example, do you like to have pure TikZ solution, without use of the pgfplots?
    – Zarko
    Jun 27 '16 at 2:26
  • Actually, I would prefer pure tikzpicture to pgfplots but either am satisfied with your code and it looks good. Thank you.
    – user28251
    Jun 27 '16 at 2:36
  • Now I added "pure TikZ" solution ...
    – Zarko
    Jun 27 '16 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.