
LaTeX 中是否有 arctan2 / atan2 函數,它可以像其他三角函數一樣印出美觀的結果\sin
\cos
...?
答案1
amsmath
提供\DeclareMathOperator{\foo}{foo}
定義新的運算子名稱,其排版類似於\sin
和\cos
, \ln
,即直立字體和正確的間距。
\atantwo
這也可以與 一起使用(2
不允許作為巨集名稱的一部分,但是,因此\atantwo
.
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\atantwo}{atan2}
\DeclareMathOperator{\arctantwo}{arctan2}
\begin{document}
\[
\atantwo ( y, x)
\]
\[
\arctantwo ( y, x)
\]
\[
\sin (x y)
\]
\end{document}
注意:此atan2(y,x)
函數決定極座標中的角度,與函數 相關但不同atan(y/x)
。兩者不可互換。此atan
函數的輸出範圍為(-pi/2,pi/2)
,而atan2
輸出範圍為(-pi,pi]
。如果x>0
,那麼atan2(y,x)=atan(y/x)
。如果x<0
,那麼atan2(y,x)=atan(y/x) +/- pi
。如果x=0
then在for或foratan(y/x)
時未定義。對於數學和常見程式語言(包括 C、FORTRAN 和 matlab), (或等效的)的這個定義是相同的。atan2(y,x)=pi/2
y>0
-pi/2
y<0
atan2
arctan2
答案2
如果你願意,你可以讓他們變得更聰明一點來啟用\atan2
和\arctan2
\long\def\gobbleone#1{}
\protected\def\atan{\futurelet\tmptoken\doatan}
\protected\def\doatan{\operatorname{atan\ifx\tmptoken22\fi}%
\ifx\tmptoken2\expandafter\gobbleone\fi}
\protected\def\arctan{\futurelet\tmptoken\doarctan}
\protected\def\doarctan{\operatorname{arc\,tan\ifx\tmptoken22\fi}%
\ifx\tmptoken2\expandafter\gobbleone\fi}
$\atan2(y, x) \arctan2(y, x) \sin(x, y)$