I'm trying to draw the functions y=(0.05*0.4+0.1*2*x)/(0.05+0.1*2) and x=-0.1/(2*10*(y - 0.1))+y, by using tikz as follows

\begin{axis}[xmin=0,xmax=1,ymin=0,ymax=1, samples=1000, xlabel={$c$}, ylabel={$s$}]
\addplot[blue, ultra thick] (x,(0.05*0.4+0.1*2*x)/(0.05+0.1*2));
\addplot[red,  ultra thick] (-0.1/(2*10*(x - 0.1))+x,x);

I obtained the picture:

enter image description here

But I'm not sure about the result (tikz seems to have drawn also the asymptote of second function). For me (and Mathematica) the result should be instead the following:

enter image description here

Can anybody tell me what's wrong with this picture and my tikz code?

  • 1
    Add appropriate curly brackets: \addplot[blue, ultra thick] (x,{(0.05*0.4+0.1*2*x)/(0.05+0.1*2)}); \addplot[red, ultra thick] ({-0.1/(2*10*(x - 0.1))+x},x);. – user121799 Mar 16 at 18:18

The TikZ/pgfplots parser gets confused about the brackets, it does not know which of them are delimiters of coordinates or expressions in the functions. So you have to help them a bit by adding curly brackets.

 \begin{axis}[xmin=0,xmax=1,ymin=0,ymax=1, samples=1000, xlabel={$c$},
 ylabel={$s$},unbounded coords=discard]
  \addplot[blue, ultra thick] (x,{(0.05*0.4+0.1*2*x)/(0.05+0.1*2)});
  \addplot[red,  ultra thick,domain=0:0.099] ({-0.1/(2*10*(x - 0.1))+x},x);
  \addplot[red,  ultra thick,domain=0.11:1] ({-0.1/(2*10*(x - 0.1))+x},x);

enter image description here

  • Thank you! It's clear. Is there a way to remove the asymptote? – Mark Mar 16 at 20:05
  • @Mark Sure. (Sorry, was offline.) I removed the red asymptote. If you want to remove the blue one as well, remove \addplot[blue, ultra thick] (x,{(0.05*0.4+0.1*2*x)/(0.05+0.1*2)});. The red one was because you plotted over a singularity at x=0.1, and one easy way to remove it is to add two separate plots that avoid it. – user121799 Mar 16 at 22:28

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.