3

I tried to plot a function like this

enter image description here

f(x)= (sin(x)^2)*(cos((x/2)^2)) on a tiny bandwidth around 180 degrees

on various tools like PyXPlot, Asymptote and GNUPlot, I'm not expert in any of these but all tools give me almost the same result, the result is inaccurate as at x=180, y=0.I tried to plot with more samples but with no success.

2
  • 2
    Many plot programs use radians as default for sine and cosine - in which case your function is not 0 at x=180 - notice the period of your fuction in the above picture corresponds to this. Some programs provide a sind function instead for degrees, otherwise you have to scale x by Pi/180. Commented Mar 3, 2013 at 11:51
  • Welcome to TeX.sx! I would use pst-plot. Commented Mar 3, 2013 at 11:56

2 Answers 2

3

run with xelatex

\documentclass{article}
\usepackage{pst-plot}
\begin{document}

\psset{xunit=2cm,yunit=4}
\begin{pspicture}(-3.3,-0.2)(3.3,1)
\psaxes[]{->}(0,0)(-3.2,-0.2)(3.2,1)[$x$,90][$y$,0]
\psplot[algebraic,plotpoints=100,plotstyle=LineToXAxis,
  linecolor=red,linewidth=1pt]{-3.2}{3.2}{(sin(x)^2)*(cos((x/2)^2))}
\psplot[algebraic,plotpoints=1000,linestyle=dashed,
  linewidth=1pt]{-3.2}{3.2}{(sin(x)^2)*(cos((x/2)^2))}
\end{pspicture}
\end{document}

enter image description here

0
1

Run with any compiler:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7} 

\begin{document} 
\begin{tikzpicture}
\begin{axis}[
    axis lines*=middle,
    samples=11,
    domain=179.9:180.1
]
\addplot [thick, smooth]  {(sin(x)^2)*(cos((x/2)^2))};
\end{axis}  
\end{tikzpicture} 
\end{document}
0

You must log in to answer this question.

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