如何使用 Pgftools 繪製 z=sqrt(x^2-y^2) 圖形?我相信我已經在網路上找到了所有建議,但都無濟於事

如何使用 Pgftools 繪製 z=sqrt(x^2-y^2) 圖形?我相信我已經在網路上找到了所有建議,但都無濟於事

我嘗試使用參數符號(即({x},{y},{sort(x^2-y^2)})繪製它,如下面的程式碼所示,但沒有任何內容呈現圖形計算器上顯示的圖像。

\begin{tikzpicture}[scale=1.5]
\begin{axis}[
grid=major,
3d box=complete,
enlargelimits=false,
colormap/cool,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
zlabel style = {sloped like x axis}
]
\addplot3 [
surf,
shader=faceted,
samples=50,
z buffer=sort,
]  {sqrt((x)^2-(y)^2)};

\end{axis}
\end{tikzpicture}

答案1

你幾乎做對了所有事情,pgfplots但不太擅長取負數的平方根。所以如果你稍微調整一下網域,你就會得到

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
grid=major,
3d box=complete,
enlargelimits=false,
colormap/cool,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
zlabel style = {sloped like x axis}
]
\addplot3 [domain=2:4,domain y=-2:2,
surf,
shader=faceted,
samples=50,
z buffer=sort,
]  {sqrt(x^2-y^2)};

\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

至於你在評論中的要求,可以將函數寫為sqrt(u*v), whereu=x+yv=x-y。然後x=(u+v)/2y=(u-v)/2。由於變數只是參數圖中的佔位符,因此我們可以分別將u和重新命名vxy,並得出

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[xmax=2,xmin=-2,
grid=major,
3d box=complete,
enlargelimits=false,
colormap/cool,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
zlabel style = {sloped like x axis}
]
\addplot3 [domain=0:4,domain y=0:4,
surf,
shader=faceted,
samples=50,
z buffer=sort,
] ({(x+y)/2},{(x-y)/2},{sqrt(x*y)});
\addplot3 [domain=0:4,domain y=0:4,
surf,
shader=faceted,
samples=50,
z buffer=sort,
] ({-(x+y)/2},{-(x-y)/2},{sqrt(x*y)});

\end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容