Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is my code at the moment:

% Rest of document omitted brevity...
\subsection*{f(x) = cosec(x)}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
  mark=none,
  domain=0:360,
  samples=500,
  smooth}, % All plots: 50 samples, smooth, no marks
  axis x line=middle,
  axis y line=center,
  xmin=0,
  xmax=360,
  ymin=-1,
  ymax=1,
  enlargelimits=upper] % extend the axes a bit to the right and top
  \addplot {1 / sin(x)};
\end{axis}
\end{tikzpicture}
% Rest of document omitted brevity...

This looks right to me, however, when I try and compile, I get: C:/Users/Todd/Dropbox/Homework/Notes/A-level_Maths/Core 3/Graphs/Graphs.tex:111: Dimension too large. [\end{axis}]

When I change \addplot {1 / sin(x)}; to \addplot {sin(x)}; the document compiles without any issues. What am I doing wrong?

share|improve this question
2  
You are dividing one by zero. –  percusse Jan 20 '13 at 19:36
    
Ahhh yes of course! –  Todd Davies Jan 20 '13 at 19:37

2 Answers 2

up vote 9 down vote accepted

Some remarks about what are you trying to achieve:

  • Consider using degrees as an argument for trigonometric functions via deg(x)-pgfplots function.
  • After using deg(x) the domain and range of x-axes should be rescaled.
  • Don't forget the \pgfplotsset{compat=1.7} in document preamle. =)
  • Use cosec(x) function instead of 1 / sin(x).

Finally we've got (included all, wrapped in standalone):

\documentclass{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
      mark=none,
      domain=0:10,
      samples=500,
      smooth}, % All plots: 50 samples, smooth, no marks
  axis x line=middle,
  axis y line=center,
  xmin=0,
  xmax=10,
  ymin=-10,
  ymax=10,
  enlargelimits=upper] % extend the axes a bit to the right and top
  \addplot {cosec(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

And the result:

enter image description here

share|improve this answer
    
Nice answer, It would appear that using deg(x) fixes the problem –  Todd Davies Jan 20 '13 at 19:46

Problem is on x=k*pi, 1/sin(x) is undefined (or as your error suggests "too large" because the package plots it numerically) . You can solve this problem by using restrict y to domain:

\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
  restrict y to domain=-10:10,
  mark=none,
  domain=-360:360,
  samples=500,
  smooth}, % All plots: 50 samples, smooth, no marks
  axis x line=middle,
  axis y line=center,
  xmin=-360,
  xmax=360,
  ymin=-10,
  ymax=10,
  enlargelimits=upper] % extend the axes a bit to the right and top
  \addplot {1/sin(x)};
\end{axis}
\end{tikzpicture}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.