问题在于
找到 x 必须满足的条件,以使表达式对于 x 的所有实值都为正。
结果是:
这是我的 MWE:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=7, nodes={
execute at begin node=$,
execute at end node=$
}]
\draw[->, thick] (-0.8,0) -- (0.8,0) node[above] {x};
\foreach \x/\xpar/\xtext in {
-0.5 / \bullet / -5,
-0.1 / \bullet / -1,
0 / \circ / 1,
0.2 / \bullet / \frac{3}{2},
0.3 / \bullet / 2,
0.6 / \circ / 4
} \draw[thick] (\x,0pt) node {\xpar} node[below=5pt] {\xtext};
\node[circle,blue,fill=white,draw,inner sep=2pt] at (0,0) {};
\end{tikzpicture}
\end{document}
我怎样才能实现这个目标?
答案1
这里有两个建议,它们可以接近您的绘图,但不必精确地复制它。
两者的共同点是在foreach
循环中添加一个变量,如果区间是解,则该变量\sol
等于,否则(如果您不能轻松使用)。1
-1
boolean
它们都使用库curve to
的操作topaths
(参见手册 3.0.1a 第 748 页)。
第一个定义曲线的出口角和入口角:
to[out=\sol*-60,in=\sol*-120]
第二个使用以下controls
选项:
to [controls=+(-90:1) and +(-90:1)]
第一个建议:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[nodes={
execute at begin node=$,
execute at end node=$
}]
\draw[->, thick] (-6,0) -- (5,0) node[above] {x};
\clip(-6,-1)rectangle(4.5,1.5);
\foreach \x/\xpar/\xtext/\sol [remember=\x as \lastx (initially -7)] in {
-5 / \bullet / -5/1,
-1 / \bullet / -1/-1,
0 / \circ / 1/1,
1.5 / \bullet / \frac{3}{2}/1,
2 / \bullet / 2/-1,
4 / \circ / 4/1,
7/\circ/7/-1
}
{\ifnum \sol=1
\draw[thick,pattern=north east lines] (\lastx,0)to[out=\sol*-60,in=\sol*-120](\x,0) node {\xpar} node[below=5pt] {\xtext};
\else
\draw[thick] (\lastx,0)to[out=\sol*-60,in=\sol*-120](\x,0) node {\xpar} node[below=5pt] {\xtext};
\fi
}
\node[circle,blue,fill=white,draw,inner sep=2pt] at (0,0) {};
\end{tikzpicture}
\end{document}
第二项建议:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[nodes={
execute at begin node=$,
execute at end node=$
}]
\draw[->, thick] (-6,0) -- (5,0) node[above] {x};
\clip(-6,-1)rectangle(4.5,1.5);
\foreach \x/\xpar/\xtext/\sol [remember=\x as \lastx (initially -7)] in {
-5 / \bullet / -5/1,
-1 / \bullet / -1/-1,
0 / \circ / 1/1,
1.5 / \bullet / \frac{3}{2}/1,
2 / \bullet / 2/-1,
4 / \circ / 4/1,
6/\circ/6/-1
}
{\ifnum \sol=1
\draw[thick,pattern=north east lines] (\lastx,0)to [controls=+(-90:1) and +(-90:1)](\x,0) node {\xpar} node[below=15pt] {\xtext};
\else
\draw[thick] (\lastx,0)to [controls=+(90:1) and +(90:1)](\x,0) node {\xpar} node[below=15pt] {\xtext};
\fi
}
\node[circle,blue,fill=white,draw,inner sep=2pt] at (0,0) {};
\end{tikzpicture}
\end{document}
答案2
我认为你想要的是一幅卡通画,而不是画出函数(在这个域中有极点)。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[scale=7, nodes={
execute at begin node=$,
execute at end node=$
}]
\draw[->, thick] (-0.8,0) -- (0.8,0) node[above] {x};
\foreach \x/\xpar/\xtext [count=\Z] in {
-0.5 / \bullet / -5,
-0.1 / \bullet / -1,
0 / \circ / 1,
0.2 / \bullet / \frac{3}{2},
0.3 / \bullet / 2,
0.6 / \circ / 4
} \draw[thick] (\x,0pt) coordinate (p-\Z) node {\xpar} node[below=5pt] {\xtext};
\node[circle,blue,fill=white,draw,inner sep=2pt] at (0,0) {};
\draw[pattern=north east lines] (-0.8,-0.1) to[out=0,in=-135] (p-1) --(-0.8,0);
\draw (p-1) to[out=45,in=135] (p-2);
\draw[pattern=north east lines] (p-2) to[out=-45,in=-135,looseness=2] (p-3);
\draw[pattern=north east lines] (p-3) to[out=-45,in=-135,looseness=1.2] (p-4);
\draw (p-4) to[out=45,in=135,looseness=2] (p-5);
\draw[pattern=north east lines] (p-5) to[out=-45,in=-135,looseness=1] (p-6);
\draw (p-6) to[out=45,in=180] ++ (0.2,0.1);
\end{tikzpicture}
\end{document}