1

Im trying to do a hyperbola with the a tangent in the middle, more or less like this, centered in x=4 and y=3
enter image description here

but I can get only this
enter image description here

the MWE is

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}

\begin{tikzpicture}
  \datavisualization[
    school book axes,
    visualize as smooth line/.list={left,right},
    x axis={length=6cm, ticks and grid={major also at=4}},
    y axis={length=6cm, ticks={some}},
    data/format=function
  ]
    data[set=left] {
      var x : interval [0:3.9] samples 84;
      func y = 1 / (\value x - 4);
    }
    data[set=right] {
      var x : interval[4.1:8] samples 84;
      func y = 1 / (\value x - 4);
    };
    \addplot [mark=none,draw=violet,ultra thick,smooth,domain=0:360] {-1*tan(\x)};
\end{tikzpicture}

\end{document}  

I usually give the trigonometric functions arguments in degress, but lately it seems to work without a domain, and went well too. But this time seems not to work the tangent- The main problem is that I cant work the hyperbola to get up to y=3. Perhaps it is needs to declare the axis section, but I wonder if this will conflict with the custom definitions of the hyperbola thingys.

2
  • 1
    You just need to add 3 to the expression for y; then, when x goes to infinity, y goes to 3. – Daniel N Jan 21 at 22:08
  • I was doing that way, but the asypmtotes remained the same – riccs_0x Jan 21 at 23:07
2

I propose the solution below. It is based on pgfplots. enter image description here

  • I tried to figure out the functions you are interested in from your code.
  • It is a good practice to use the same technique for similar things (here the two graphs).
  • It is better to give the domain for your graphs; in this way, you control what you are doing.

The code

\documentclass[border=1cm]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    font=\scriptsize,
    axis background style={fill=gray!5},
    grid=major,
    grid style={color=gray!50},
    xtick={0,1,...,8},
    ytick={-6,-3,...,12},
    axis lines=center
    ]
    \addplot[mark=none, draw=violet, thick, smooth,
    domain=-.2:{.86+pi/2}, samples=100] {-tan(deg(x-1))};
    \addplot[mark=none, draw=violet, thick, smooth,
    domain={1.08+pi/2}:{.86+3*pi/2}, samples=100] {-tan(deg(x-1))};
    \addplot[mark=none, draw=violet, thick, smooth,
    domain={1.08+3*pi/2}:8.2, samples=100] {-tan(deg(x-1))};
    
    \addplot[mark=none, draw=red, thick, smooth, domain=-.2:3.9, samples=100]
    {1/(x-4) +3};    
    \addplot[mark=none, draw=red, thick, smooth, domain=4.1:8.2, samples=100]
    {1/(x-4) +3};    
  \end{axis}
\end{tikzpicture}

\end{document}
2
  • Thanks so much,the first time I try to do this , I was thinking it would be easy,but unexpectedly, it was so hard to crack down, with the hyperbola never get to level up it and the tangent was a matter or try and error,do you use some method to aproximate a expression for the function based on the graph? – riccs_0x Jan 22 at 22:35
  • 1
    Hi. No method really; I've just noticed that the green graph in the image you posted was similar to -tan(x) and that the value at 1 was 0. Maybe your problems were implied by the different ways you were handling the two graphs; there were different "coordinate systems" involved. – Daniel N Jan 23 at 9:53

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.