![如何使用 tikz 绘制类似 \frac{1}{sqrt{1-x^2}} 的曲线?](https://linux22.com/image/398383/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20tikz%20%E7%BB%98%E5%88%B6%E7%B1%BB%E4%BC%BC%20%5Cfrac%7B1%7D%7Bsqrt%7B1-x%5E2%7D%7D%20%E7%9A%84%E6%9B%B2%E7%BA%BF%EF%BC%9F.png)
如果有人能帮助我绘制该函数图我将非常感激\frac{1}{\sqrt{1-x^2}}
。
答案1
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\f(#1){1/sqrt(1-(#1)^2)}
\draw[->] (-2,0)--(2,0) node[below]{$x$};
\draw[->] (0,-.5)--(0,3) node[left]{$y$};
\draw[dashed] (-1,-.5)--(-1,3) (1,-.5)--(1,3);
\draw[blue,smooth] plot[domain=-.93:.93,samples=200] (\x,{\f(\x)});
\path
(1,0) node[below right]{1}
(-1,0) node[below left]{-1}
(0,1) node[below right]{1};
\end{tikzpicture}
\end{document}
答案2
这是使用该pgfplots
包的另一种方法。
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
unit vector ratio = {1 1},
grid = none,
tick style = {black},
% x axis
xmin = -2, xmax = 3,
axis x line = middle,
x axis line style = -{Stealth},
xlabel = $x$,
xlabel style = {below},
xtick = {-1, ..., 2},
xticklabels = {},
extra x ticks = {1},
% y axis
ymin = -2, ymax = 6,
axis y line = middle,
y axis line style = -{Stealth},
ylabel = $y$,
ylabel style = {left},
ytick = {-1, ..., 5},
yticklabels = {},
extra y ticks = {1}
]
\addplot[domain = -0.99 : 0.99, samples = 1000] {1 / sqrt(1 - x^2)};
\end{axis}
\end{tikzpicture}
\end{document}
由于选择的样本数量较多,因此需要一些时间进行编译。