atan2는 pgfplots에서 작동하지 않습니다

atan2는 pgfplots에서 작동하지 않습니다

을 사용하여 두 사인파의 진폭과 인수를 진폭 및 위상 측면에서 플롯하려고 하면 pgfplotsatan2 함수(에서 지원됨)를 컴파일하는 동안 오류가 나타납니다 pgfmath. 여기에 예가 있습니다

\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
title={$\sqrt{x^2+1-2x\cos(y)}$},
xlabel=$x$, ylabel=$y$,
]
\addplot3[surf,domain=0:1,domain y=0:360,]
{sqrt(x^2+1-2*x*cos(y))};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
  title={$atan2(-\sin(y),x-cos(y)$},
 xlabel=$x$, ylabel=$y$,
]
\addplot3[surf,domain=0:1,domain y=0:360,]
{atan2(-sin(y),x-cos(y)};
  %{sqrt(x^2+1-2*x*cos(y))};
\end{axis}
\end{tikzpicture}

\end{document}

오류는 다음과 같습니다.

    (line 31) Illegal unit of measure (pt inserted) {atan2(-sin(y),x-cos(y)}

그리고

    (line 31) Missing = inserted for \ifdim. {atan2(-sin(y),x-cos(y)}

여러 번 반복

답변1

다른 사람들이 이미 언급했듯이, PGF와 함께 제공되는 FPU(부동 소수점 처리 장치)에는 현재 atan2 구현이 없습니다(하나를 구현해야 합니다. 이는 버그입니다).

해결 방법은 pgfplotsFPU를 사용하지 않도록 구성하는 것입니다. 이는 문제의 이미지에 적용됩니다(그러나 일반적으로 데이터 범위 + 정밀도를 모두 제한하므로 권장되지 않습니다).

\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.10}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
  title={$atan2(-\sin(y),x-cos(y)$},
 xlabel=$x$, ylabel=$y$,
 use fpu=false
]
\addplot3[surf,domain=0:1,domain y=0:360,]
{atan2(-sin(y),x-cos(y))};
  %{sqrt(x^2+1-2*x*cos(y))};
\end{axis}
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

답변2

atan2fpu 구현인 것처럼 가장하는 PGF 함수로 폴백하여 가짜로 만들 수 있습니다 .

\documentclass[]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\makeatletter
\pgfmathdeclarefunction{myatan2}{2}{%
\begingroup%
  \pgfmathfloattofixed{#1}\edef\tempa{\pgfmathresult}%
  \pgfmathfloattofixed{#2}%
  \pgfkeys{pgf/fpu=false}%
  \pgfmathparse{atan2(\tempa,\pgfmathresult)}\pgfkeys{/pgf/fpu}%
  \pgfmathfloatparsenumber{\pgfmathresult}%
  \pgfmath@smuggleone\pgfmathresult%
\endgroup
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  title={$atan2(-\sin(y),x-cos(y)$},
 xlabel=$x$, ylabel=$y$,
]
\addplot3[surf,domain=0:1,domain y=0:360]
{myatan2({-sin(y)},{x-cos(y)})};
  %{sqrt(x^2+1-2*x*cos(y))};
\end{axis}
\end{tikzpicture}
\end{document}

출력은 John Kormylo의 이미지와 동일합니다.

답변3

제가 사분면을 제대로 파악한 것 같아요.

atan2

\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  title={$atan2(-\sin(y),x-cos(y))$},
 xlabel=$x$, ylabel=$y$,
]
\addplot3[surf,domain=0:1,domain y=0:360,]
{x == cos(y) ? ( -sin(y) > 0 ? 90: -90) :
 (x > cos(y) ? atan(-sin(y)/(x-cos(y))): 
 (-sin(y) > 0 ? 180+atan(-sin(y)/(x-cos(y))): atan(-sin(y)/(x-cos(y)))-180))};
\end{axis}
\end{tikzpicture}

\end{document}

관련 정보