5

I would like to graph the function x^(x-1) but I keep running into errors. Instead of a xy plane, it just graphs the x axis. Here is the general set up.

\documentclass{standalone}

\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat = newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xmin = 0, xmax = 15,
    ymin = 0, ymax = 30000,
    xtick distance = 3,
    ytick distance = 6000,
    width = \textwidth,
    height = \textwidth,
    xlabel = {$x$},
    ylabel = {$y$},]

\addplot[
    domain = 2:15,
    samples = 50,
    smooth,
    thick,
    brown,
] {x^(x-1)};

\end{axis}
\end{tikzpicture}
\end{document}

It keeps throwing the following errors:

  • Missing number, treated as zero
  • Missing number, treated as zero
  • Illegal unit of measure (pt inserted)
  • Package pgfplots Error: The argument(s) for ytick resulted in a tick distance which is too small. Please reconfigure the xtick argument(s)
  • Package pgfplots Warning: Axis range for axis y is approximately empty; enlarging it (it is [0.0:0.0]) on input line 27.
  • Package pgfplots Warning: the ticklabel anchor cannot be determined, the normal vector -(-1.0pt,0.0pt) and the unit x vector (1.0pt,0.0pt) are almost parallel (abs(cos(angle)) = 1.0pt)! on input line 27.
  • Package pgfplots Warning: the ticklabel anchor cannot be determined, the normal vector -(1.0pt,0.0pt) and the unit y vector (1.0pt,0.0pt) are almost parallel (abs(cos(angle)) = 1.0pt)! on input line 27.
  • Package pgfplots Warning: the ticklabel anchor cannot be determined, the normal vector -(-1.0pt,0.0pt) and the unit y vector (1.0pt,0.0pt) are almost parallel (abs(cos(angle)) = 1.0pt)! on input line 27.
  • Package pgfplots Warning: the ticklabel anchor cannot be determined, the normal vector -(0.0pt,-1.0pt) and the unit y vector (0.0pt,-1.0pt) are almost parallel (abs(cos(angle)) = 1.0pt)! on input line 27.

Things that I have tried so far for the equation:

{pow(e,(x-1))}
{exp((x-1)*ln(x))}
{exp(multiply((x-1),ln(x)))}
2
  • Try ymax=30e15 ytick distance=6e15
    – gigiair
    Commented Aug 7, 2022 at 21:37
  • The width of x-axis and the height of y-axis shall be \textwith which is 345pt=~12,2cm with the standalone-class. || The function to plot is y=x^(x-1). ymax=30000 is reached for x=~6,50516. For x=15 you get y=29192926025390625. So seems either the domain is too large and thus in y-direction things are calculated for a few orders of magnitude more than you actually want to see on the plot. Or ymax and ytick distance are far too small. You can try domain =2:6.50517. Or instead try something like ymax=29192926025390625 and ytick distance=5000000000000000. Commented Aug 7, 2022 at 22:35

3 Answers 3

3
\documentclass{standalone}

\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat = newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
   xmin = 0,%
   xmax = 15,%
   ymin = 0,%
   ymax = 30e15,%
   xtick distance = 3,%
   ytick distance = 6e15,%
  width = \textwidth,%
  height = \textwidth,%
  xlabel = {$x$},%
  ylabel = {$y$}%
  ]%
%
  \addplot[%
  domain = 2:15,%
  samples = 100,%
  smooth,%
  thick,%
  brown%
    ]%
    {x^(x-1)};%
%
\end{axis}
\end{tikzpicture}
\end{document}

graphe

4
  • That’s not the correct graph. If you you a graphing calculator like Desmos, x^(x-1) should tend toward infinity as x->0. Commented Aug 8, 2022 at 2:39
  • 2
    @DevanoBethel Increase samples. At samples=100 it will be evaluated at the smallest point being 15/100=0.15 where x**(x-1) is still small. In order to get to 10**16 you need x to be sampled at the point 10**-16 which is a bit impractical.
    – user202729
    Commented Aug 8, 2022 at 6:40
  • Exactly, because the y axis ticks are too large, so you won’t be able to see it rising Commented Aug 8, 2022 at 14:52
  • 1
    @Devano Bethel: since the kx domain is 2:15, x should not tend toward 0. :
    – gigiair
    Commented Aug 8, 2022 at 16:08
3

I use f(x)=x^{x-1}=\exp{(x-1)log(x)} for x>0. The global minimum point is (1,1). Both Asymptote and TikZ code, plain ones, are given below.

enter image description here

// http://asymptote.ualberta.ca/
unitsize(1.5cm,3.5mm);
import graph;
real f(real x){return exp((x-1)*log(x));}

label(scale(.8)*"$1$",(1,0),S);
label(scale(.8)*"$1$",(0,1),W);
draw((1,0)--(1,1)--(0,1),dashed);
draw(Label("$x$",align=SE,EndPoint),(-.5,0)--(3.5,0),Arrow(TeXHead));
draw(Label("$y$",align=
           W,EndPoint),(0,-1.5)--(0,10),Arrow(TeXHead));
label("$O$",align=SW,(0,0));

path p=graph(f,.09,3);
draw(Label("$f(x)=x^{x-1}$",align=W,Relative(.8)),p,magenta+1pt);

shipout(bbox(5mm,invisible));

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[x=1.5cm,y=4mm]
\tikzset{declare function={f(\x)=exp((\x-1)*ln(\x));}}      
\draw[dashed]  
(1,0) node[scale=.8,below]{$1$}--(1,1)
(0,1) node[scale=.8,left]{$1$}--(1,1)
(0,0) node[below left]{$O$}
;
\draw[->] (-.5,0)--(3.2,0) node[below right]{$x$};
\draw[->] (0,-1.5)--(0,10) node[left]{$y$};
\draw[smooth,red,thick] plot[domain=.09:3] (\x,{f(\x)});
\fill (1,1) circle(1.5pt);
\end{tikzpicture}
\end{document}
2

The problem is that the domain is too high at 0:15, 15^14 is too high for the graph to calculate. Try this code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=left,
xlabel=\(x\),
ylabel={\(f(x)\)},
]

\addplot[
  domain=0:4,
  samples=200,
  smooth,
  thick,
  color=brown
    ]
    {x^(x-1)};
\end{axis}
\end{tikzpicture}
\end{document}

Which gives: image

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .