Drawing tanx=1/x Graph with Tikz from 0 to 10pi

In summary, in order to produce a graph of the equation tanx = 1/x on the interval [0,10\pi], you can use Tikz and follow the instructions in section 19.5 of the manual for v. 2.10. However, since tan(x) may behave differently across the vertical asymptotes, it may be necessary to draw it separately on each interval using the foreach command or reduce the interval using the clip command. Additionally, to label every pi/2 on the graph, you can use the foreach command and specify the labels explicitly or iterate over natural numbers with a given step. Adjustments can be made by using an arithmetic expression inside a coordinate and printing text can be done using either the node
  • #1
Dustinsfl
2,281
5
How can I get Tikz to produce this, tanx = 1/x, graph from [0,10\pi]?
 
Physics news on Phys.org
  • #2
What do you mean by a graph of an equation? Do you want to draw the graphs of tan(x) and 1/x on that interval? See section 19.5 of the manual for v. 2.10. I am not sure how tan(x) would behave across the vertical asymptotes. It may be necessary to draw it on each interval $(-\pi/2+k\pi,\pi/2+k\pi)$ separately using the foreach command. You may need to reduce each interval or use the clip command to limit the graph vertically
 
  • #3
Evgeny.Makarov said:
What do you mean by a graph of an equation? Do you want to draw the graphs of tan(x) and 1/x on that interval? See section 19.5 of the manual for v. 2.10. I am not sure how tan(x) would behave across the vertical asymptotes. It may be necessary to draw it on each interval $(-\pi/2+k\pi,\pi/2+k\pi)$ separately using the foreach command. You may need to reduce each interval or use the clip command to limit the graph vertically

Thanks. I tried but I couldn't get it to work.
 
  • #4
dwsmith said:
How can I get Tikz to produce this, tanx = 1/x, graph from [0,10\pi]?
Use Desmos! (Click on the graph to enlarge it.)

[graph]hsieolxfjp[/graph]
 
  • #5
Opalg said:
Use Desmos! (Click on the graph to enlarge it.)

[graph]hsieolxfjp[/graph]

I made one in Mathematica but I looking to make it for a LaTex document. If I can make it with Tikz, it will look nicer than
\includegraphics in LaTex.
 
  • #6
Code:
 \usetikzlibrary{arrows}
  \begin{tikzpicture}[>=stealth',x=.5cm,y=.5cm]
 \def\npi{3.1416}
 \def\periods{4}
 \draw[->] (-\npi/2,0) -- ({(\periods+.5)*\npi},0) node[below] {$x$};
 \draw[->] (0,-10) -- (0,10) node[left] {$y$};
 \clip (-\npi/2,-9.8) rectangle ({(\periods+.5)*\npi},9.8);
 \draw[thick,domain=0.05:{(\periods+.4)*\npi},samples=300,smooth] plot (\x,1/\x);
 \foreach \n in {0,...,4}
 \draw[thick,shift={(\npi*\n,0)},domain=-\npi/2+.1:\npi/2-.1,samples=100,smooth] plot (\x,{tan(\x r)});
 \end{tikzpicture}

gives

View attachment 355

For a better quality, it may make sense to use gnuplot to compute the coordinates as described in the TikZ manual.
 

Attachments

  • tan1.png
    tan1.png
    4.3 KB · Views: 53
  • #7
Evgeny.Makarov said:
Code:
 \usetikzlibrary{arrows}
  \begin{tikzpicture}[>=stealth',x=.5cm,y=.5cm]
 \def\npi{3.1416}
 \def\periods{4}
 \draw[->] (-\npi/2,0) -- ({(\periods+.5)*\npi},0) node[below] {$x$};
 \draw[->] (0,-10) -- (0,10) node[left] {$y$};
 \clip (-\npi/2,-9.8) rectangle ({(\periods+.5)*\npi},9.8);
 \draw[thick,domain=0.05:{(\periods+.4)*\npi},samples=300,smooth] plot (\x,1/\x);
 \foreach \n in {0,...,4}
 \draw[thick,shift={(\npi*\n,0)},domain=-\npi/2+.1:\npi/2-.1,samples=100,smooth] plot (\x,{tan(\x r)});
 \end{tikzpicture}

gives

View attachment 355

For a better quality, it may make sense to use gnuplot to compute the coordinates as described in the TikZ manual.
Is there a command to tell it to label every pi/2 on the graph?
 
  • #8
dwsmith said:
Is there a command to tell it to label every pi/2 on the graph?
No, you'll need to do this using the \foreach command. I believe this was discussed in a recent thread.
 
  • #9
Code:
\foreach \x in {0,\pi/2,...,5\pi}
\draw (\x,0) n\pi/2 (0.5cm);
Is this correct? Nope. This didn't work.
Isn't that saying from 0 to 5\pi increment by \pi/2 and at the location (x,0) draw n\pi/2 the size of .5cm?
 
Last edited:
  • #10
I have not tested this code.

Code:
%draw the ticks
\foreach \x in {1,...,10} \draw (\x*\npi/2,2pt) -- (\x*\npi/2,-2pt);
%draw labels n\pi/2 for odd n >= 3
\foreach \x in {3,5,...,9} \node[below] at (\x*\npi/2,0) {$\frac{\x\pi}{2}$};
%draw labels n\pi for n >= 2
\foreach \x in {2,...,5} \node[below] at (\x*\npi,0) {$\x\pi$};
\node[below] at (\npi/2,0) {$\frac{\pi}{2}$};
\node[below] at (\npi,0) {$\pi$};

It is also possible to use one \foreach, but since the labels are slightly different, I am not sure about ellipsis. All labels may need to be given explicitly.
Code:
\foreach \x/\xtext in {1/\frac{\pi}{2},2/\pi,3/\frac{3\pi}{2},4/2\pi} {
  \draw (\x*\npi/2,2pt) -- (\x*\npi/2,-2pt);
  \node at (\x*\npi/2,0) {$\xtext$};
}
 
  • #11
Evgeny.Makarov said:
I have not tested this code.

Code:
%draw the ticks
\foreach \x in {1,...,10} \draw (\x*\npi/2,2pt) -- (\x*\npi/2,-2pt);
%draw labels n\pi/2 for odd n >= 3
\foreach \x in {3,5,...,9} \node[below] at (\x*\npi/2,0) {$\frac{\x\pi}{2}$};
%draw labels n\pi for n >= 2
\foreach \x in {2,...,5} \node[below] at (\x*\npi,0) {$\x\pi$};
\node[below] at (\npi/2,0) {$\frac{\pi}{2}$};
\node[below] at (\npi,0) {$\pi$};

It is also possible to use one \foreach, but since the labels are slightly different, I am not sure about ellipses. All labels may need to be given explicitly.
Code:
\foreach \x/\xtext in {1/\frac{\pi}{2},2/\pi,3/\frac{3\pi}{2},4/2\pi} {
  \draw (\x*\npi/2,2pt) -- (\x*\npi/2,-2pt);
  \node at (\x*\npi/2,0) {$\xtext$};
}

If I add (0.25cm), will it adjust the text size?
 
  • #12
dwsmith said:
If I add (0.25cm), will it adjust the text size?

I made some adjustments and got it.
 
  • #13
dwsmith said:
Code:
\foreach \x in {0,\pi/2,...,5\pi}
First, \pi is a predefined command in TeX. Second, the \foreach command is both powerful and fickle. I am not sure it can recognize the pattern in 0,\pi/2,...,5\pi. The safest way is to (1) give all variants explicitly, separated by commas, (2) iterate over natural numbers, as in \foreach \x in {1, ..., 10} or (3) iterate over natural numbers with a given step, as in \foreach \x in {1,3, ..., 9}. Then you can use \x in an arithmetic expression inside a coordinate. For more information, see the section about \foreach (I believe it is in the chapter about utilities).

dwsmith said:
Code:
\draw (\x,0) n\pi/2 (0.5cm);
To print text, use either

\draw (1,1) node {$x$};

or

\node at (1,1) {$x$};
 

FAQ: Drawing tanx=1/x Graph with Tikz from 0 to 10pi

What is Tikz and how is it used to draw graphs?

Tikz is a powerful graphics package for LaTeX that allows for the creation of high-quality diagrams and figures. It is commonly used in scientific and mathematical documents to create precise and customizable graphs, such as the tanx=1/x graph from 0 to 10pi.

What is the significance of drawing the tanx=1/x graph from 0 to 10pi?

The tanx=1/x graph from 0 to 10pi is important in mathematics as it represents the behavior of the tangent function over a wider range of values. It can also be used to illustrate concepts such as asymptotes and periodicity.

What is the process for drawing the tanx=1/x graph with Tikz?

To draw the tanx=1/x graph with Tikz, you will need to first define the function using mathematical notation and then use Tikz commands to plot points and connect them with a smooth curve. It is important to specify the domain (0 to 10pi) and range of the graph to ensure accuracy.

Are there any tips for drawing the tanx=1/x graph with Tikz?

It is recommended to break the graph into smaller sections, such as from 0 to pi, pi to 2pi, and so on, to make it easier to plot and connect points. Additionally, using a grid or axis can help with accurately placing points and ensuring the graph is symmetrical.

Can I customize the appearance of the tanx=1/x graph with Tikz?

Yes, Tikz offers a variety of customization options for graphs, such as changing the color, thickness, or style of the curve, adding labels and annotations, and adjusting the scale of the axes. This allows for the creation of visually appealing and informative graphs.

Similar threads

Replies
1
Views
1K
Replies
3
Views
2K
  • Poll
Replies
11
Views
2K
Replies
5
Views
2K
Replies
8
Views
6K
Replies
4
Views
2K
Back
Top