![동기 부여](https://rvso.com/image/400377/%EB%8F%99%EA%B8%B0%20%EB%B6%80%EC%97%AC.png)
저는 TikZ를 처음 접한 이후로 한동안 GeoGebra를 사용하여 그림을 그렸습니다. 지금까지는 코드가 엄청나게 복잡하기는 하지만 GeoGebra로 만든 그림에는 문제가 없습니다. 그런데 이번에는 해결할 수 없는 오류가 발생했습니다.
오류 메시지는 다음과 같습니다.
Dimension too large.
<to be read again>
\relax
l.34 \end{axis}
I can't work with sizes bigger than about 19 feet. Continue and I'll use the largest value I can.
해당 메시지를 받았지만 여기에 표시된 줄거리를 볼 수 있습니다.
내 (복잡한) 코드는 다음과 같습니다.
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm, scale = 1.2, transform shape]
\begin{axis}[
x=1.0cm,y=1.0cm,
axis lines=middle,
xmin=-1.129485186780251,
xmax=5.72744433329757,
ymin=-0.96997054991852,
ymax=5.616499082403562,
xtick={0.0},
ytick={0.0}, restrict y to domain=-0.96997054991852:5.616499082403562,]
\clip(-1.129485186780251,-0.76997054991852) rectangle (5.82744433329757,5.916499082403562);
\draw[line width=0.8pt,smooth,samples=100,domain=-3.129485186780251:10.42744433329757] plot(\x,{(\x)-2.25E-50});
\draw[line width=0.8pt,smooth,samples=100,domain=-3.129485186780251:10.42744433329757] plot(\x,{0-0.07123888916965247*(\x)^(4.0)+1.5096421986752417*(\x)^(3.0)-9.579592272284225*(\x)^(2.0)+23.93776936035761*(\x)-17.586966972004486});
\draw (5.196549774492815,0.49322601353710884) node[anchor=north west] {$x$};
\draw (0.020629571335991016,5.575885328535428) node[anchor=north west] {$f(x)$};
\draw [line width=0.8pt,dash pattern=on 2pt off 2pt] (1.5,1.5)-- (1.5,0.);
\draw [line width=0.8pt,dash pattern=on 2pt off 2pt] (3.,0.)-- (3.,3.);
\draw [line width=0.8pt,dash pattern=on 2pt off 2pt] (4.5,4.5)-- (4.501485877435332,0.);
\draw (1.2137496293807978,0.021729881572188525) node[anchor=north west] {$x_0$};
\draw (2.700437452518166,0.021729881572188525) node[anchor=north west] {$x_1$};
\draw (4.228710949030006,0.021729881572188525) node[anchor=north west] {$x_2$};
\begin{scriptsize}
\draw [fill=black] (1.5,1.5) circle (1.2pt);
\draw [fill=black] (4.5,4.5) circle (1.2pt);
\draw [fill=black] (3.,3.) circle (1.2pt);
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}
비슷한 오류 메시지를 보고하는 사용자가 있었습니다. 가끔 추가하면 restrict y to domain
문제가 해결된 것 같았는데, 제 경우에는 그렇지 않은 것 같습니다. 누구든지 내 문제를 해결하는 데 도움을 줄 수 있나요?
답변1
IMHO GeoCobra는 그래프를 그리는 데 사용되지 않는 도구입니다. 함수를 플롯하고 싶다면,pgfplots
로드하는 것이 적합하지만 이해하지 못하고 이러한 오류를 생성하는 일부 블랙박스의 출력이 전부는 아닙니다. 오히려 함수를 플롯하면 됩니다.케이Z는 교차점 등을 찾습니다.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:5,axis lines=middle,ymin=-1,ymax=6,xticklabels={},
yticklabels={},xlabel={$x$},ylabel={$f(x)$}]
\addplot[no marks,smooth,name path=curve]{0.5*(x-2)^3-0.5*(x-2)^2+2.25};
\addplot[no marks,name path=line]{x};
\path (0,0) coordinate (O);
\draw[dashed,name intersections={of=curve and line,total=\t}]
foreach \X in {1,...,\t} {(intersection-\X) node[circle,fill,inner sep=1pt]{}
-- (intersection-\X|-O) node[below]{$x_{\the\numexpr\X-1}$}};
\end{axis}
\end{tikzpicture}
\end{document}
따라서 이것은 기술적인 의미에서 귀하의 질문에 대한 실제 답변은 아니지만 문제를 체계적으로 해결할 수 있는 대안이 존재하는 경우 GeoCobra와 같은 것을 사용하지 않도록 설득하려는 시도입니다.
답변2
동기 부여
현재 허용되는 답변은 이유를 설명하지 않습니다.
Dimension too large
restrict y to domain
OP의 예에서는 작동하지 않습니다.
더욱이, 곡선을 자르기 위해 주로 하드 코딩에 의존합니다 ( 이 단락의 나머지 부분에서는 x domain
간단히 " "라고 부릅니다 ). domain
적절한 domain
. (다항식/지수) 곡선은 전체 그래프의 오른쪽/왼쪽 부분에서 빠르게 증가/감소할 수 있습니다. 적합한 domain
.
논의
오류를 세 부분으로 분석하겠습니다.
- 최소 문제 사례(MPE)
- 최대 PGF 크기
- 에 대한 간략한 설명
restrict y to domain
MPE
생성된 TikZ 코드의 줄 대부분은 양호합니다. 즉, 오류 메시지에 영향을 주지 않고 올바른 줄을 삭제할 수 있습니다.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-5,
xmax=13.6,
ymin=-5,
ymax=6.55,
]
\clip (-5,-5) rectangle (13.6,6.55);
\draw (-4.9,-4.9) rectangle (13.3,6.5);
\draw[domain=-5:13.6] plot (\x,{1/2*(\x)^3-2*\x});
\end{axis}
\end{tikzpicture}
\end{document}
내 MPE와 코드 사이의 사소한 차이점은 다음과 같습니다.
\documentclass
그림을 확대하고 불필요한 주변 공백을 제거하는standalone
대신 입니다 .article
compat=1.18
compat=1.15
내 PDFLaTeX가 제안하는 대신 .- 읽기 쉽도록 숫자를 소수점 이하 두 자리로 반올림했습니다.
- 여기서 가져왔습니다
restrict y to domain={...}
. 이를 내 MPE에 다시 추가하더라도 컴파일러에서는 동일한 오류가 발생합니다. 이에 대해서는 이 섹션의 마지막 하위 섹션에서 자세히 설명하겠습니다. - 및 에서
x=1cm
및 를 모두 제거했지만 TikZ 및 PGF 플롯의 기본값이므로 괜찮습니다.y=1cm
\begin{tikzpicture}
\begin{axis}
시각적 출력을 남겨두겠습니다.
pdftoppm -png graph.pdf > graph.png
다음 하위 섹션으로 이동합니다.
이 시점에서 우리는이 질문은 이것에 관한 것이 아닙니다대지브라, 위의 MPE는 Geometry 제품군 없이 구성될 수 있기 때문입니다.
최대 PGF 크기
그만큼관련 질문에 대한 답변이 승인되었습니다. \usepgflibrary{fpu}
TeX 차원의 가능한 가장 큰 값인 600cm
보다 크다는 것을 보여줍니다 . 이지만 보다 크므 로 길이로 사용하면 오류가 발생합니다 .\maxdimen
\maxdimen
(2^14-2e-5)pt = 16383.99998pt
600cm
17000pt
600cm
Dimension too large
주어진 3차 곡선은 다음과 같이 정의됩니다.와이=엑스³/2 - 2엑스[-5,13.6]에 있습니다. 언제엑스= 13,와이= 1072.5 > 600. 이후 x=1cm
및y=1cm
으로와이-coordinate가 1072.5cm
로 변환되면 pt
을 초과하여 \maxdimen
오류가 발생합니다.
에 대한 간략한 설명restrict y to domain
키는 (섹션 4.22)에서 찾을 수 있습니다.좌표 건너뛰기 또는 변경 – 필터of) PGF 플롯 매뉴얼이 있지만 TikZ 매뉴얼에는 없습니다. 이것을 뒤로 미루려고 했는데 \draw[]
시스템이 키를 인식하지 못했습니다 /tikz/restrict y to domain
. 나는 또한 이것을 뒤에 두려고 시도했지만 plot
도움이 되지 않았습니다. 왜냐하면 \draw
PGF Plots 명령 대신 TikZ 명령이기 때문입니다.
restrict y to domain
안에 넣으면 이 PGF Plots 키가 이 환경 내부의 모든 (또는 ) \begin{axis}
에 적용되지만 요소에는 적용되지 않습니다.\addplot
\addplot+
axis
\draw
해결책
실제로 당신의 문제를 해결하기 전에 먼저 간단한 문제를 해결하겠습니다.
MPE
\draw[domain={...}] plot (\x,{...});
로 전환하다 \addplot[domain={...}] (x,{...});
.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-5,
xmax=13.6,
ymin=-5,
ymax=6.55,
restrict y to domain=-5:6.55,
]
\clip (-5,-5) rectangle (13.6,6.55);
\draw (-4.9,-4.9) rectangle (13.3,6.5);
\addplot[domain=-5:13.6] (x,{1/2*(x)^3-2*x});
\end{axis}
\end{tikzpicture}
\end{document}
제한이 완전히 사용되지는 않았지만 적어도 컴파일러는 더 이상 불평하지 않습니다.
곡선을 늘리려면 가 [3*ymin,3*ymax]
적합한 것으로 나타났습니다 y domain
. 스케일링 요소가 2
여기서 작동하지 않는다는 것을 모르겠습니다 .
이 접근 방식은 프로그래밍하기가 훨씬 쉽습니다. 의 발생을 검색(정규식) \begin{axis}[
한 다음 " " 줄을 삽입할 수 있습니다 restrict y to domain=xxx:yyy
. 프로그래밍 방식으로 숫자 값 을 추출할 수 있는 xxx
및 yyy
에서 상한 및 하한을 계산하는 함수를 개발할 수 있습니다 . 예를 들어, 저는 단순히 두 숫자에 .ymin
ymax
3
원본 예
대괄호 안의 내용을 건드리지 않고 를 포함 하는 \draw [...] plot (\x,{...})
코드 두 줄만 변경했습니다 .\addplot [...] (x,{...})
\x
x
[...]
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm, scale = 1.2, transform shape]
\begin{axis}[
x=1.0cm,y=1.0cm,
axis lines=middle,
xmin=-1.129485186780251,
xmax=5.72744433329757,
ymin=-0.96997054991852,
ymax=5.616499082403562,
xtick={0.0},
ytick={0.0}, restrict y to domain=-0.96997054991852:5.616499082403562,]
\clip(-1.129485186780251,-0.76997054991852) rectangle (5.82744433329757,5.916499082403562);
\addplot[line width=0.8pt,smooth,samples=100,domain=-3.129485186780251:10.42744433329757] (x,{(x)-2.25E-50});
\addplot[line width=0.8pt,smooth,samples=100,domain=-3.129485186780251:10.42744433329757] (x,{0-0.07123888916965247*(x)^(4.0)+1.5096421986752417*(x)^(3.0)-9.579592272284225*(x)^(2.0)+23.93776936035761*(x)-17.586966972004486});
\draw (5.196549774492815,0.49322601353710884) node[anchor=north west] {$x$};
\draw (0.020629571335991016,5.575885328535428) node[anchor=north west] {$f(x)$};
\draw [line width=0.8pt,dash pattern=on 2pt off 2pt] (1.5,1.5)-- (1.5,0.);
\draw [line width=0.8pt,dash pattern=on 2pt off 2pt] (3.,0.)-- (3.,3.);
\draw [line width=0.8pt,dash pattern=on 2pt off 2pt] (4.5,4.5)-- (4.501485877435332,0.);
\draw (1.2137496293807978,0.021729881572188525) node[anchor=north west] {$x_0$};
\draw (2.700437452518166,0.021729881572188525) node[anchor=north west] {$x_1$};
\draw (4.228710949030006,0.021729881572188525) node[anchor=north west] {$x_2$};
\begin{scriptsize}
\draw [fill=black] (1.5,1.5) circle (1.2pt);
\draw [fill=black] (4.5,4.5) circle (1.2pt);
\draw [fill=black] (3.,3.) circle (1.2pt);
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}
그래프의 중앙이 매우 작은 것을 확인하세요.
할 것
다음을 위해 몇 가지 문자열 조작 작업을 수행할 시간입니다.
- 모든 소수점 이하 두 자리로 반올림필요하다면
- 출력 이미지를 더 크게 만들려면
[10pt]{article}
to로 바꾸세요 .{standalone}
restrict y domain={...},
피하기 위해 주입합니다Dimensions too large
.