Geogebra for Tikz 的代码错误

Geogebra for Tikz 的代码错误

我尝试对这段代码进行多次修改,但没有看到错误。有人能帮我吗?

\documentclass[10pt]{article}

\usepackage{pgf,tikz}

\usetikzlibrary{arrows}

\pagestyle{empty}

\begin{document}

\definecolor{ffffqq}{rgb}{1,1,0}

\definecolor{qqccqq}{rgb}{0,0.8,0}

\definecolor{ffttzz}{rgb}{1,0.2,0.6}

\definecolor{ttttff}{rgb}{0.2,0.2,1}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]

\draw[->,color=black] (-1.11,0) -- (1.09,0);
\foreach \x in {-1,-0.8,-0.6,-0.4,-0.2,0.2,0.4,0.6,0.8,1}

\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};

\draw[->,color=black] (0,-0.03) -- (0,1.14);
\foreach \y in {,0.2,0.4,0.6,0.8,1}

\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};

\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-1.11,-0.03) rectangle (1.09,1.14);

\draw[color=ttttff, smooth,samples=100,domain=-1.0:1.0] plot(\x,{1-abs((\x))+0.1*2.718281828^((-1)/0.1)*(1-2.718281828^((1-abs((\x)))/0.1))});

\draw (0.62,0.98) node[anchor=north west] {$$\varepsilon= 1/10$$};

\draw[color=ffttzz, smooth,samples=100,domain=-1.0:1.0] plot(\x,{1-abs((\x))+0*(1-2.718281828^((1-abs((\x)))/0.05))});

\draw [line width=1.2pt,color=ffttzz] (0.57,0.86)-- (0.46,0.86);

\draw (0.62,0.91) node[anchor=north west] {$$\varepsilon= 1/20$$};

\draw[color=qqccqq, smooth,samples=100,domain=-1.0:1.0] plot(\x,{1-abs((\x))+0*(1-2.718281828^((1-abs((\x)))/0.03))});

\draw [line width=1.2pt,color=qqccqq] (0.58,0.72)-- (0.47,0.72);

\draw (0.62,0.78) node[anchor=north west] {$$\varepsilon= 1/40$$};

\draw[color=ffffqq, smooth,samples=100,domain=-1.0:1.0] plot(\x,{1-abs((\x))+0*(1-2.718281828^((1-abs((\x)))/0.04))});

\draw [line width=1.2pt,color=ffffqq] (0.57,0.78)-- (0.47,0.78);

\draw (0.62,0.85) node[anchor=north west] {$$\varepsilon= 1/25$$};

\draw (-1,0)-- (0,1);

\draw (1,0)-- (0,1);

\draw [line width=1.2pt,color=ttttff] (0.44,0.97)-- (0.45,0.67);

\draw [line width=1.2pt,color=ttttff] (0.45,0.67)-- (0.84,0.66);

\draw [line width=1.2pt,color=ttttff] (0.84,0.66)-- (0.84,0.97);

\draw [line width=1.2pt,color=ttttff] (0.84,0.97)-- (0.44,0.97);

\draw [line width=1.2pt,color=ttttff] (0.57,0.92)-- (0.46,0.92);

\end{tikzpicture}

\end{document}

答案1

有几个问题。

两个都很容易解决。

首先,不要在 后留空行\foreach。TikZ 希望读到循环末尾而不中断任何段落。

其次,切勿$$在 LaTeX 文档中使用。这样做会使 TikZ 产生混淆,但无论如何,这样做都是不好的。在这种情况下,只需将$$s改为$s 即可。

第三个不太容易解决,你需要决定你的意思以及你需要做什么。你指定的图超出了 TeX 可以处理的最大尺寸。为了让代码编译,我不得不注释掉这些:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{ffffqq}{rgb}{1,1,0}
\definecolor{qqccqq}{rgb}{0,0.8,0}
\definecolor{ffttzz}{rgb}{1,0.2,0.6}
\definecolor{ttttff}{rgb}{0.2,0.2,1}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
  \draw[->,color=black] (-1.11,0) -- (1.09,0);
  \foreach \x in {-1,-0.8,-0.6,-0.4,-0.2,0.2,0.4,0.6,0.8,1}
  \draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
  \draw[->,color=black] (0,-0.03) -- (0,1.14);
  \foreach \y in {,0.2,0.4,0.6,0.8,1}
  \draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
  \draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
  \clip(-1.11,-0.03) rectangle (1.09,1.14);

%   \draw[color=ttttff, smooth,samples=100,domain=-1.0:1.0] plot(\x,{1-abs((\x))+0.1*2.718281828^((-1)/0.1)*(1-2.718281828^((1-abs((\x)))/0.1))});

  \draw (0.62,0.98) node[anchor=north west] {$\varepsilon= 1/10$};

%   \draw[color=ffttzz, smooth,samples=100,domain=-1:1] plot(\x,{1-abs((\x))+0*(1-2.718281828^((1-abs((\x)))/0.05))});

  \draw [line width=1.2pt,color=ffttzz] (0.57,0.86)-- (0.46,0.86);
  \draw (0.62,0.91) node[anchor=north west] {$\varepsilon= 1/20$};

%   \draw[color=qqccqq, smooth,samples=100,domain=-1.0:1.0] plot(\x,{1-abs((\x))+0*(1-2.718281828^((1-abs((\x)))/0.03))});

  \draw [line width=1.2pt,color=qqccqq] (0.58,0.72)-- (0.47,0.72);
  \draw (0.62,0.78) node[anchor=north west] {$\varepsilon= 1/40$};

%   \draw[color=ffffqq, smooth,samples=100,domain=-1.0:1.0] plot(\x,{1-abs((\x))+0*(1-2.718281828^((1-abs((\x)))/0.04))});

  \draw [line width=1.2pt,color=ffffqq] (0.57,0.78)-- (0.47,0.78);
  \draw (0.62,0.85) node[anchor=north west] {$\varepsilon= 1/25$};
  \draw (-1,0)-- (0,1);
  \draw (1,0)-- (0,1);
  \draw [line width=1.2pt,color=ttttff] (0.44,0.97)-- (0.45,0.67);
  \draw [line width=1.2pt,color=ttttff] (0.45,0.67)-- (0.84,0.66);
  \draw [line width=1.2pt,color=ttttff] (0.84,0.66)-- (0.84,0.97);
  \draw [line width=1.2pt,color=ttttff] (0.84,0.97)-- (0.44,0.97);
  \draw [line width=1.2pt,color=ttttff] (0.57,0.92)-- (0.46,0.92);
\end{tikzpicture}
\end{document}

答案2

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows,calc}
\usepackage{calc}
\pagestyle{empty}
\begin{document}

\definecolor{ffffqq}{rgb}{1,1,0}
\definecolor{qqccqq}{rgb}{0,0.8,0}
\definecolor{ffttzz}{rgb}{1,0.2,0.6}
\definecolor{ttttff}{rgb}{0.2,0.2,1}

\footnotesize
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=6.0cm,y=6.0cm]

\draw[->,color=black] (-1.11,0) -- (1.09,0);
\foreach \x in {-1,-0.8,-0.6,-0.4,-0.2,0.2,0.4,0.6,0.8,1}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {$\x$};

\draw[->,color=black] (0,-0.03) -- (0,1.14);
\foreach \y in {,0.2,0.4,0.6,0.8,1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {$\y$};

\draw[color=black] (0pt,-10pt) node[right] {$0$};
\clip(-1.11,-0.03) rectangle (1.09,1.14);
\draw[color=ttttff, smooth,samples=100,domain=-1:-.1] plot(\x,{1-abs((\x))+0.1*2.718281828^((-1)/0.1)*(1-2.718281828^((1-abs(\x))/0.1))});

\draw (0.62,0.98) node[anchor=north west] {$\varepsilon= 1/10$};
\draw[color=ffttzz, smooth,samples=100,domain=-1:1] plot(\x,{1-abs(\x)});
\draw [line width=1.2pt,color=ffttzz] (0.57,0.86)-- (0.46,0.86);

\draw (0.62,0.91) node[anchor=north west] {$\varepsilon= 1/20$};
\draw[color=qqccqq, smooth,samples=100,domain=-1:1] plot(\x,{1-abs((\x))});

\draw [line width=1.2pt,color=qqccqq] (0.58,0.72)-- (0.47,0.72);
\draw (0.62,0.78) node[anchor=north west] {$\varepsilon= 1/40$};
\draw[color=ffffqq, smooth,samples=100,domain=-1:1] plot(\x,{1-abs((\x))});
\draw [line width=1.2pt,color=ffffqq] (0.57,0.78)-- (0.47,0.78);
\draw (0.62,0.85) node[anchor=north west] {$\varepsilon= 1/25$};

\draw (-1,0)-- (0,1);
\draw (1,0)-- (0,1);

\draw [line width=1.2pt,color=ttttff] (0.44,0.97)-- (0.45,0.67);
\draw [line width=1.2pt,color=ttttff] (0.45,0.67)-- (0.84,0.66);
\draw [line width=1.2pt,color=ttttff] (0.84,0.66)-- (0.84,0.97);
\draw [line width=1.2pt,color=ttttff] (0.84,0.97)-- (0.44,0.97);
\draw [line width=1.2pt,color=ttttff] (0.57,0.92)-- (0.46,0.92);

\end{tikzpicture}

\end{document}

0除了@cfr 提到的注释之外,我认为这里真正的问题是在第一个表达式的域中包含:

plot(\x,{1-abs((\x))+0.1*2.718281828^((-1)/0.1)*(1-2.718281828^((1-abs(\x))/0.1))})

如果 ,上述表达式中的最后一个括号2.718281828^((1-abs(\x))/0.1))计算为22026.4657576099> 。pgfmanual 说明如下:16383.99999\x = 0

需要注意的是,所有计算在任何时候都不能超过 ± 16383.99999,因为底层计算依赖于 TeX 维度。这意味着许多底层计算必然是近似的,而且速度也不是很快。毕竟,TeX 是一种排版语言,不太适合相对高级的数学运算。但是,可以按照第 76 节所述更改计算

根据 TeX Book

16383.99998 pt(TeX 的最大尺寸)

为了解决这个问题,您可以在这个域的一半上各绘制两个图,例如-1:-.1.1:1

要放大图片使用x=6.0cm,y=6.0cm并进行\footnotesize全局设置。

相关内容