I want to plot this function (excuse me, I don't know how to write equations on this forum):

f(x) = -2*arccos(0.5*e^(ln(4)/x) -1) + pi

When I enter the code (shown below) in pgfplots, I get a error that says "dimension too large". I've tried to put x, and the whole inside of the arccos in deg(), I've restricted the y domain to 2:8 (so it is continues), but nothing seems to work. The only way I don't get an error, is by removing the deg(). However, then I get an empty grid where no function is shown. Does anyone know how to get this function plotted?

    \begin{tikzpicture}[scale=1.3, transform shape]
    \begin{axis}[xmin=-8, xmax=8, ymin=-4, ymax=4, restrict y to domain=-8:1, axis x line=center, axis y line=center]
    \addplot[color=blue, samples=100, domain=2:8]
    {-2*acos( 0.5*e^(ln(4)/x) -1 )+pi};

Here you can find how the plot should look like.

  • In your definition of f(x) I see an exponential function, but in the code below you write 2^... Is this a typo or which function are you exactly trying to plot? – Sito Dec 9 '18 at 16:40

I don't understand what you exactly wanted to do with the ydomain, since your function only depends on x. The problem was that the acos functions returns the answer in degrees, but you want it in rad (if I understood you correctly). See this answer. Also, I'm not sure if one could handle the domain problem better, but since your x is in the denominator, you have a problem at x=0. I just split the domain into two parts, feel free to change the bounds as necessary for you. Hope this works for you.

    \addplot[color=blue, samples=100, domain=1:8]
    {pi -2.0 * rad(acos(0.5 * exp(ln(4.0)/x) - 1.0))};
    \addplot[color=red, samples=100, domain=-8:-0.1]
    {pi -2.0 * rad(acos(0.5 * exp(ln(4.0)/x) - 1.0))};
| improve this answer | |
  • It works, thanks! A friend helped me with other graphs, and in those graphs restricting the y domein worked, but it doesn't really make sense in this case, indeed. – Aka Foefje Dec 9 '18 at 21:13

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.