30 利用tikz绘制min,max函数,有现成的宏包吗?还是只能手动分段绘制

发布于 2025-07-30 16:15:35
\documentclass[a4paper,border=2pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{math,calc,intersections,arrows.meta}
\tikzset{every picture/.style={samples=300,smooth,line join=round,thick,>=Stealth,font=\small}}

\begin{document}

  \begin{tikzpicture}[scale=.45]
    \tikzmath{\ai=2;\aii=-1;}
    \draw[->](-2.5,0)--(3.5,0)node[below]{$x$};
    \draw[->](0,-2)--(0,3.5)node[right]{$y$};
    \coordinate[label=45:$O$](O)at(0,0);
    \path[cyan,name path=fx,draw,domain=-2.5:2.5]plot(\x,{abs(\x)-1});
    \path[blue,name path=gx,draw,domain=0.5:3.5]plot(\x,{\x*\x-2*\ai*\x+\ai+2});
    \path[name intersections={of=fx and gx,by={[label=]A}}] let \p1=(A) in
    \pgfextra
      \xdef\xA{\x1/28.45274}\xdef\yA{\y1/28.45274}
    \endpgfextra;
    \draw[red,domain=-2.5:\xA]plot(\x,{abs(\x)-1});
    \draw[red,domain=\xA:3.5]plot(\x,{\x*\x-2*\ai*\x+\ai+2});
    \node[below]at(-1.2,0){$-1$};
    \node[below]at(1,0){$1$};
    \node[below]at(2,0){$2$};
  \end{tikzpicture}

\end{document}

min函数.png

min.tex
我想得到的结果是上面图片中两个函数中最小者的图象。现在只会利用name intersections得到交点,再分段绘制图象,不知道有没有其它绘图思路,求助各位大神,谢谢!

查看更多

关注者
0
被浏览
89
Sagittarius Rover
我要成为Typst糕手/(ㄒoㄒ)/~~

可以直接用pgfplots:

\documentclass[a4paper,border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=middle,
    xlabel=$x$,
    ylabel=$y$,
    xmin=-3, xmax=5,
    ymin=-2, ymax=5,
    samples=300,
    smooth,thick,
    grid=major,
    grid style={gray!30},
]
    \addplot[cyan, dashed, domain=-3:5] {abs(x) - 1};
    \addplot[violet, dotted, domain=-3:5] {(x-2)^2};
    \addplot[red, ultra thick, domain=-3:5] {min(abs(x)-1, (x-2)^2)};
\end{axis}
\end{tikzpicture}
\end{document}

image.png

「函数图像」和「平面欧几里得图形」是不太一样的,应该选择最合适的工具。

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览