LaTeX 中如何使用 arctan2 / atan2 函數?

LaTeX 中如何使用 arctan2 / atan2 函數?

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=0then在for或foratan(y/x)時未定義。對於數學和常見程式語言(包括 C、FORTRAN 和 matlab), (或等效的)的這個定義是相同的。atan2(y,x)=pi/2y>0-pi/2y<0atan2arctan2

答案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)$

答案3

另一種選擇是使用\mathrm.所以:

$\mathrm{atan2}$
$\mathrm{arctan2}$

這使

在此輸入影像描述

在此輸入影像描述

相關內容