我看过这个答案,但它似乎不起作用:
\documentclass[10pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
%<<<<<<<WARNING>>>>>>>
% PGF/Tikz doesn't support the following mathematical functions:
% cosh, acosh, sinh, asinh, tanh, atanh,
% x^r with r not integer
% Plotting will be done using GNUPLOT
% GNUPLOT must be installed and you must allow Latex to call external
% programs by adding the following option to your compiler
% shell-escape OR enable-write18
% Example: pdflatex --shell-escape file.tex
\begin{document}
\definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
\definecolor{dtsfsf}{rgb}{0.8274509803921568,0.1843137254901961,0.1843137254901961}
\definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
\definecolor{sexdts}{rgb}{0.1803921568627451,0.49019607843137253,0.19607843137254902}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=1.3267631992181441,
xmax=3.0815031792940615,
ymin=-1.2315594843495015,
ymax=0.428590551805931,
xtick={1.4000000000000001,1.5000000000000002,...,3},
ytick={-1.2000000000000002,-1.1,...,0.4},]
\clip(1.3267631992181441,-1.2315594843495015) rectangle (3.0815031792940615,0.428590551805931);
\draw[line width=0.8pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.10000000149011612] {[smooth,samples=50,domain=2.475353221098382:3.1415926535899534] plot(\x,{sin(((\x))*180/pi)+cos(((\x))*180/pi)})} -- (3.1415926535899534,-1.6019374007595787E-13) {-- plot[raw gnuplot, id=func0] function{set parametric ; set samples 100; set trange [2.475353221098382:3.1415926535899534]; plot 5.616945874688335-t,sin((5.616945874688335-t)*180/pi)+tan((5.616945874688335-t)*180/pi)}} -- (2.475353221098382,-0.1681173890090787) -- cycle;
\draw[line width=0.8pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.10000000149011612] { plot[raw gnuplot, id=func1] function{set samples 100; set xrange [3.1415926535899534:3.9269908169715837]; plot sin((x)*180/pi)+tan((x)*180/pi)}} -- (3.9269908169715837,0.292893218771065) {-- plot[raw gnuplot, id=func2] function{set parametric ; set samples 100; set trange [3.1415926535899534:3.9269908169715837]; plot 7.068583470561537-t,cos((7.068583470561537-t)*180/pi)+tan((7.068583470561537-t)*180/pi)}} -- (3.1415926535899534,-1.6019374007595787E-13) -- cycle;
\draw[line width=2pt,color=sexdts,smooth,samples=100,domain=1.3267631992181441:3.0815031792940615] plot(\x,{sin(((\x))*180/pi)+cos(((\x))*180/pi)});
\draw[line width=2pt,color=rvwvcq,smooth,samples=100,domain=1.3267631992181441:3.0815031792940615] plot(\x,{sin(((\x))*180/pi)+tan(((\x))*180/pi)});
\draw[line width=2pt,color=dtsfsf,smooth,samples=100,domain=1.3267631992181441:3.0815031792940615] plot(\x,{cos(((\x))*180/pi)+tan(((\x))*180/pi)});
\begin{scriptsize}
\draw[color=sexdts] (2.100856413751085,0.296357671019132) node {$f$};
\draw[color=rvwvcq] (2.0101272838681714,-1.0529968351118533) node {$g$};
\draw[color=dtsfsf] (2.9811220143172217,-1.081952940393634) node {$h$};
\draw [fill=wrwrwr] (2.475353221098382,-0.1681173890090787) circle (2.5pt);
\draw[color=wrwrwr] (2.490798631545733,-0.1264014660948676) node {$A$};
\draw [fill=wrwrwr] (3.1415926535899534,-1.00000000000016) circle (2.5pt);
\draw[color=wrwrwr] (3.1567890530266918,-0.9584068911913692) node {$B$};
\draw [fill=wrwrwr] (3.9269908169715837,0.2928932187932085) circle (2.5pt);
\draw[color=wrwrwr] (3.9424647096723446,0.3349658113948398) node {$C$};
\draw[color=rvwvcq] (2.8575759651149566,-0.28083402759769854) node {$a = -0.377$};
\draw[color=rvwvcq] (3.461793361994783,-0.2750428065413424) node {$b = 0.414$};
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}
这是从 GeoGebra 导出的具有复杂函数的内容
我收到以下错误:
(c:/texlive/2022/texmf-dist/tex/latex/jknapltx/ursfs.fd)
! Dimension too large.
<to be read again>
\relax
l.55 \end{axis}
?
我尝试减少小数位数,缩小 tikzpicture,但无济于事。
答案1
正如@ManuelCart 在评论中指出的那样,错误的直接原因是未定义 tan(90 度)=tan(((pi/2)*180/pi)。您必须限制涉及的函数的范围,使其tan(((\x))*180/pi)})
不小于 1.58。(1.571 也可以……)
您的代码中有相当多的格式选择是不寻常的。我建议您剪辑图像,使其左下角点为 (1.5,-2.0),右上角点为 (4.0,0.5)。此外,我建议您将三条主要曲线的标签设置得比“f”、“g”和“h”更具信息量;请参阅以下屏幕截图了解具体的替代建议。最后,5 条指令中的第 2 条\draw
似乎没有任何作用;这是多余的吗?
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
%\usepackage{mathrsfs} % why?
\usetikzlibrary{arrows}
\pagestyle{empty}
\definecolor{wrwrwr}{rgb}{0.3804,0.3804,0.3804}
\definecolor{dtsfsf}{rgb}{0.8275,0.1843,0.1843}
\definecolor{rvwvcq}{rgb}{0.0824,0.3961,0.7529}
\definecolor{sexdts}{rgb}{0.1804,0.4902,0.1961}
\begin{document}
\begin{tikzpicture}[line cap=round, line join=round,
>=triangle 45, x=3cm, y=3cm]
\begin{axis}[
x=3cm, y=3cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin= 1.5, xmax= 4.0,
ymin=-2.0, ymax= 0.5,
xtick={1.5,2,...,4},
ytick={-2.0,-1.5,...,0.5},]
\clip(1.5,-2.0) rectangle (4,0.5); % is this instruction needed?
\draw[line width=0.5pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.1]
{[smooth,samples=50,domain=2.475:3.142]
plot(\x,{sin(\x*180/pi)+cos(\x*180/pi)})} -- (3.142,0)
{ -- plot[raw gnuplot, id=func0]
function{set parametric ; set samples 100; set trange [2.5:4.0];
plot 5.617-t,sin((5.617-t)*180/pi)+tan((5.617-t)*180/pi)}}
-- (2.475,-0.168) -- cycle;
%% Q: What is the following '\draw' instruction supposed to do?
%\draw[line width=0.5pt,color=rvwvcq,fill=rvwvcq,fill opacity=0.1]
% { plot[raw gnuplot, id=func1]
% function{set samples 100; set xrange [3.142:4];
% plot sin(x*180/pi)+tan(x*180/pi)}} -- (3.927,0.293)
% {-- plot[raw gnuplot, id=func2]
% function{set parametric ; set samples 100; set trange [3.142:4.0];
% plot 7.069-t,cos((7.069-t)*180/pi)+tan((7.069-t)*180/pi)}}
% -- (3.142,0) -- cycle;
\draw[line width=0.5pt,color=sexdts,smooth,samples=100,domain=1.50:4.0]
plot(\x,{sin(\x*180/pi)+cos(\x*180/pi)});
\draw[line width=0.5pt,color=rvwvcq,smooth,samples=100,domain=1.58:4.0]
plot(\x,{sin(\x*180/pi)+tan(\x*180/pi)});
\draw[line width=0.5pt,color=dtsfsf,smooth,samples=100,domain=1.58:4.0]
plot(\x,{cos(\x*180/pi)+tan(\x*180/pi)});
\scriptsize
% labels for the three main curves
\draw[color=sexdts] (2.60, 0.28) node {$f(x)=\sin x+\cos x$}; % not just "f", "g", etc
\draw[color=rvwvcq] (2.47,-1.09) node {$g(x)=\sin x+\tan x$};
\draw[color=dtsfsf] (2.71,-1.83) node {$h(x)=\cos x+\tan x$};
% labels for the three intersection points A, B, and C
\draw[fill =wrwrwr] (2.475,-0.168) circle (1.25pt);
\draw[color=wrwrwr] (2.39,-0.16) node {$A$};
\draw[fill =wrwrwr] (3.142,-1.000) circle (1.25pt);
\draw[color=wrwrwr] (3.23,-1.00) node {$B$};
\draw[fill =wrwrwr] (3.927, 0.293) circle (1.25pt);
\draw[color=wrwrwr] (3.87, 0.32) node {$C$};
% no idea about the next two instructions
\draw[color=rvwvcq] (2.87,-0.30) node {$a =-0.38$};
\draw[color=rvwvcq] (3.42,-0.30) node {$b = 0.41$};
\end{tikzpicture}
\end{document}