# How to plot dense functions smoothly and correctly

I tried to plot a function like this

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.

-
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. – Andrew Swann Mar 3 '13 at 11:51
Welcome to TeX.sx! I would use pst-plot. – Marco Daniel Mar 3 '13 at 11:56

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}


-

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
]