Graphics, Figures & TablesHow to draw this figure using Tikz?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
zmxm
Posts: 1
Joined: Thu Dec 29, 2022 8:37 pm

How to draw this figure using Tikz?

Post by zmxm »

I am trying to draw a function $f(x)=(x-0.5)(\frac{x}{x-1})^(-0.5)-x$ using Tikz. I wrote the following code:

Code: Select all

\begin{tikzpicture}[scale=0.7]
		\draw[-stealth,ultra thick] (-0.5,0)--(9,0) node[below]{$x$};
		\draw[-stealth,ultra thick] (0,-0.5)--(0, 4.5);
		\draw[color=blue, thick, domain=0:2] plot (\x, {(\x-0.5)*(\x/(\x-1))^(-0.5)-\x}) node[above, xshift=5pt, yshift=10pt]{$f(x)$};
\end{tikzpicture}
However, I got an error message saying "Dimension too large". Anyone can help? Thanks.
Last edited by Stefan Kottwitz on Fri Dec 30, 2022 1:22 pm, edited 1 time in total.
Reason: code marked

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

How to draw this figure using Tikz?

Post by Stefan Kottwitz »

Hi,

welcome to the forum!

The error occurs because TikZ uses a logarithm for calculating when a non-integer exponent is used, and that's a problem with negative values; a logarithm is not defined for negative values. Also, there's the point x=0 where a division by zero occurs. You get a plot if you change the domain, as I did here:

Code: Select all

\begin{tikzpicture}[scale=0.7]
		\draw[-stealth,ultra thick] (-0.5,0)--(9,0) node[below]{$x$};
		\draw[-stealth,ultra thick] (0,-0.5)--(0, 4.5);
		\draw[color=blue, thick, domain=1.1:8] plot (\x, {(\x-0.5)*(\x/(\x-1))^(-0.5)-\x}) node[above, xshift=5pt, yshift=10pt]{$f(x)$};
\end{tikzpicture}
Click on "Run LaTeX here" to see it.

Stefan
LaTeX.org admin
Post Reply