Graphics, Figures & Tablespgfplots | Arcsine Function Graph

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

pgfplots | Arcsine Function Graph

Post by sachinrajsharma »

Hi,

I am unable to get the output from the presented code and it is showing some error.

Code: Select all

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

y = sin^{-1}x

\begin{tikzpicture}
    \begin{axis}[
      xmin=-6,
      xmax=6,
      xlabel={$x$},
      ymin=-2,
      ymax=2,
      ylabel={$y$},
      axis x line=middle,
      axis y line=middle,
      axis line style=<->
    ]
      \addplot[no marks,blue,<->] expression[samples=100]{sin^{-1}(deg(x))};
      \addlegendentry{$y=\csc(x)$};
    \end{axis}
  \end{tikzpicture}
\end{document}
Please guide whether it is correct code to draw inverse trigonometric function graphs .


Regards,
Sachin Sharma

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots | Arcsine Function Graph

Post by localghost »

There are two mistakes in your code.
  1. For in-line math expressions you need to use the corresponding math mode.

    Code: Select all

    $y = \sin^{-1}x$
    But this is usually written with the respective math operator as $y=\arcsin(x)$.
  2. The corresponding expression for plotting is asin(x) in the actual plot command.
The corrected example.

Code: Select all

\documentclass[11pt]{standalone}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      xmin=-2,
      xmax=2,
      xlabel={$x$},
      ymin=-3,
      ymax=3,
      ylabel={$y$},
      axis x line=middle,
      axis y line=middle,
      axis line style=<->
    ]
      \addplot[domain=-1:1,no marks,blue,<->] gnuplot[samples=100] {asin(x)};
      \addlegendentry{$y=\arcsin(x)$};
    \end{axis}
  \end{tikzpicture}
\end{document}
Notes:
  • Since pgfplots is not exact enough here, let Gnuplot do the job of calculating the arcsine function (see above).
  • The domain has to be restricted to [-1,1] (see above).
Remarks:
  • Please get used to dropping irrelevant erroneous code because it distracts from the actual problem (see point #1 above).
Further reading:
  • The PGF manual (regarding allowed mathematical expressions and functions)

Thorsten
sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

pgfplots | Arcsine Function Graph

Post by sachinrajsharma »

Hi,

It is still showing the following error :

Code: Select all

! Missing number, treated as zero.
<to be read again> 
                   \pgfmath@acos@5000 
l.19 ...lue,<->] expression[samples=100]{asin(x)};
Please help.


Sachin Sharma
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots | Arcsine Function Graph

Post by localghost »

You should run the example I provided and replace expression by gnuplot.
sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

Re: pgfplots | Arcsine Function Graph

Post by sachinrajsharma »

Hi,
Thanks for your guidance , however i am still not getting the output. Could you please tell me any source wherein I can get the detail study material on drawing arctrigo function.

Thanks on this.

Regards,

Sachin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots | Arcsine Function Graph

Post by localghost »

sachinrajsharma wrote:[…] Could you please tell me any source wherein I can get the detail study material on drawing arctrigo function. […]
I have done so in my first reply under "Further reading".
Post Reply