我想使用 tikz (也许使用 pgfplots)在 LaTeX 中绘制这个方程:
(x^2+y^2) + \frac{0.7}{\sqrt((x-0.3)^2+y^2)} + \frac{0.3}{\sqrt((x+0.7)^2+y^2)} = 2.5
我试过gnuplot
:
\begin{tikzpicture}
\draw plot[raw gnuplot] function{
f(x,y) = (x**2+y**2) + 0.7/(sqrt((x-0.3)**2+y**2)) + 0.3/(sqrt((x+0.7)**2+y**2)) - 1.5;
set xrange [-4:4];
set yrange [-4:4];
set view 0,0;
set isosample 1000, 1000;
set sample 1000, 1000;
set size square;
set contour base;
set cntrparam levels incre 0,0.1,0;
unset surface;
splot f(x,y);
};
\end{tikzpicture}
我需要打开-shell-escape
:
如何启用“shell escape”(或“write18”)-Visual Studio Code(Latex Workshop 扩展)
另一方面,我尝试过pst-func
但未能绘制我的函数。
我也愿意找到任何解决方案,gnuplot
因为我不想为一个图表安装新的软件
答案1
lualatex 答案
\begin{figure}[ht!]
\centering
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
samples=40,
domain=-3:3,
axis equal=true,
axis lines=middle,
xtick=\empty,ytick=\empty,
max=3,min=-3,
xlabel={$x$},ylabel={$y$},
width=7.5cm, height=7.5cm,
]
\addplot3 [black, contour lua={levels={1.397, 1.42, 1.5, 1.6456751, 1.7782065, 1.9600748, 2.5, 3.5},labels=false}] {0.5*(x^2+y^2) + 0.7/(sqrt((x-0.3)^2+y^2)) + 0.3/(sqrt((x+0.7)^2+y^2))};
\addplot3[only marks, mark size=3.5pt] coordinates {(0.3,0,0)};
\addplot3[only marks, mark size=1.5pt] coordinates {(-0.7,0,0)};
\addplot[only marks, mark size=0.5pt] coordinates {(-0.28613,0) (-1.25673,0) (1.12321,0) (-0.2,-0.8660254) (-0.2,0.8660254)};
\end{axis}
\end{tikzpicture}
\caption{lagrange points}
\end{figure}