![atan2はpgfplotsでは動作しません](https://rvso.com/image/298786/atan2%E3%81%AFpgfplots%E3%81%A7%E3%81%AF%E5%8B%95%E4%BD%9C%E3%81%97%E3%81%BE%E3%81%9B%E3%82%93.png)
を使用して、2つの正弦波の振幅と偏角を振幅と位相でプロットしようとするpgfplots
と、atan2関数( でサポート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 が実装されていません (実装されるべきですが、これはバグです)。
回避策としてはpgfplots
、FPU を使用しないように設定することです。これは問題のイメージでは機能します (ただし、データ範囲と精度の両方が制限されるため、一般的には推奨されません)。
\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
atan2
FPU 実装を装って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
象限は正しく理解できたと思います。
\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}