我想重新创造这张图在 Latex 中,但我发现它很复杂,所以我倾向于用元帖子:
s:=1.5cm ;
vardef u(expr x,y) = (y+x*x-0.25*x*(y-1+2*x*x)) enddef ;
vardef v(expr x,y) = (-2*x*(1+y)) enddef ;
path tmparr ;
for x = -3.5 step 0.3 until 3.5 :
for y = -3.5 step 0.3 until 3.5 :
if ((x,y) = (0,0)):
else:
tmparr := (origin -- unitvector (u(x,y), v(x,y))) scaled 0.28s ;
tmparr := tmparr shifted - center tmparr ;
drawarrow tmparr shifted ((x,y) scaled s) withcolor 0.37white;
fi;
endfor ;
endfor ;
知道如何绘制抛物线y=1-2*x*x
和直线y=-1
吗?
如果除了 Metapost 之外还有人使用 Latex 来实现这一点,我将不胜感激。
答案1
新的:相图有 3 种类型:斜率场、方向场、矢量场。在这种情况下,我选择矢量长度标准化的方向场(符合我的口味 ^^,如下所示.1*unit(...)
)。
path vector(pair z) {return .1*unit((f(z.x,z.y),g(z.x,z.y)));}
更多:所选框中的剪辑允许根据 OP 的要求填充不变域。
// http://asymptote.ualberta.ca/
size(8cm);
import contour;
import graph;
real f(real x, real y) {return y+x*x-x*(y-1+2*x*x)/4;}
real g(real x, real y) {return -2x*(1+y);}
real p(real x) {return 1-2x^2;}
real a=3.5;
pair A=(-a,-a), B=(a,a);
guide[][] pf=contour(f,A,B, new real[] {0});
guide[][] pg=contour(g,A,B, new real[] {0});
path pp=graph(p,-2,2);
path invdomain=pp--(a,-a)--(a,-1)--(-a,-1)--(-a,-a)--cycle;
fill(invdomain,yellow);
// set up the vector of the vector field
path vector(pair z) {return .1*unit((f(z.x,z.y),g(z.x,z.y)));}
// set up the condition for the vector will be drawn
bool cond(pair z) {
if (g(z.x,z.y)==0) {return false;}
else {return true;}
}
add(vectorfield(vector,A,B,28,cond,paleblue,Arrow()));
draw(pf[0],blue);
draw(pg[0],magenta);
draw(pp,magenta);
clip(box(A,B));
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);
shipout(bbox(5mm,invisible));
老的:渐近线方法:隐函数的图形/轮廓/水平曲线,矢量场中的矢量(带条件)。
// http://asymptote.ualberta.ca/
size(8cm);
import contour;
import graph;
real f(real x, real y) {return y+x*x-x*(y-1+2*x*x)/4;}
real g(real x, real y) {return -2x*(1+y);}
real a=3.5;
pair A=(-a,-a), B=(a,a);
guide[][] pf=contour(f,A,B, new real[] {0});
guide[][] pg=contour(g,A,B, new real[] {0});
// set up the vector of the vector field
path vector(pair z) {return (f(z.x,z.y),g(z.x,z.y));}
// set up the condition for the vector will be drawn
bool cond(pair z) {
if (g(z.x,z.y)==0) {return false;}
else {return true;}
}
add(vectorfield(vector,A,B,20,cond,blue,Arrow()));
draw(pf[0],orange);
draw(pg[0],magenta);
//xaxis("$x$",BottomTop,LeftTicks);
//yaxis("$y$",LeftRight,RightTicks);
shipout(bbox(5mm,invisible));
答案2
我不确定这是否是您想要的,但您可以使用 Metapost 执行以下操作:
s := 1.5cm ;
vardef u(expr x,y) = (y+x*x-0.25*x*(y-1+2*x*x)) enddef ;
vardef v(expr x,y) = (-2*x*(1+y)) enddef ;
path tmparr ;
for x = -3.5 step 0.3 until 3.5 :
for y = -3.5 step 0.3 until 3.5 :
if ((x,y) = (0,0)):
else:
tmparr := (origin -- unitvector (u(x,y), v(x,y))) scaled 0.28s ;
tmparr := tmparr shifted - center tmparr ;
drawarrow tmparr shifted ((x,y) scaled s) withcolor 0.37white;
fi;
endfor ;
endfor ;
% parabola
vardef f(expr x) = (1-2*x*x) enddef ;
path tmppara ;
tmppara = (-1.5, f(-1.5)) for x = -1.5 step 0.01 until 1.5: .. (x, f(x)) endfor ;
draw tmppara scaled s withcolor red ;
% line
draw (-3.5,-1) scaled s -- (3.5,-1) scaled s withcolor red ;
使用 PGFplots 的方法是:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=-3.5:3.5, ymin=-3.5, view={0}{90}]
\addplot3 [quiver={
u={(y+x*x-0.25*x*(y-1+2*x*x))/
veclen(-2*x*(1+y), y+x*x-0.25*x*(y-1+2*x*x))},
v={(-2*x*(1+y))/
veclen(-2*x*(1+y), y+x*x-0.25*x*(y-1+2*x*x))},
scale arrows=0.28
}, -stealth, samples=20] {0};
\addplot [smooth, red] {1-2*x*x};
\addplot [smooth, red] {-1};
\end{axis}
\end{tikzpicture}
\end{document}
我不确定抛物线和直线是否正确,并且箭筒可能需要一些调整......
在这种情况下可能没有必要,但通常要绘制隐函数,可以使用gnuplot
PGF 机制(也许可以浏览此站点以获取更多示例):
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=-3.5:3.5, ymin=-3.5, ymax=3.5, view={0}{90}]
\addplot3 [quiver={
u={(y+x*x-0.25*x*(y-1+2*x*x))/
veclen(-2*x*(1+y), y+x*x-0.25*x*(y-1+2*x*x))},
v={(-2*x*(1+y))/
veclen(-2*x*(1+y), y+x*x-0.25*x*(y-1+2*x*x))},
scale arrows=0.28
}, -stealth, samples=20] {0};
\addplot [smooth, red] {1-2*x*x};
\addplot [smooth, red] {-1};
\addplot3 [raw gnuplot, smooth, blue] gnuplot {
set contour base;
set cntrparam levels discrete 0.003;
unset surface;
splot y+x*x-0.25*x*(y-1+2*x*x);
};
\end{axis}
\end{tikzpicture}
\end{document}
至于 Metapost,我不得不承认,我不确定在没有参数化的情况下是否可以轻松绘制隐函数。