
f
我有在閉區間定義的分段線性函數的程式碼,[-4, 12].
我將圖像縮放了2/5
。
在同一張圖上,我想繪製另一個g
代表$\int_{2}^{x} f(t) \, dt$
任意數字的分段函數$-4 \leq x \leq 12$
。它涉及在 的域的六個不同“部分”上繪製拋物線f
。我在程式碼中有這些命令,前面有%
.透過執行這些命令中的任何一個,我都會收到一條錯誤訊息。
我知道這一點,f
並且g
可以使用 輕鬆繪製pgfplots
。不過,我希望能夠使用 來繪製它們TikZ
。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%A piecewise linear function is drawn over the interval [-4, 12]. (The figure is magnified by 2/5.)
\draw ({-4*(2/5)},{-4*(2/5)}) -- (0,{4*(2/5)}) -- ({2*(2/5)},0) -- ({4*(2/5)},{4*(2/5)}) -- ({8*(2/5)},{-4*(2/5)})
-- ({10*(2/5)},0) -- ({12*(2/5)},{-4*(2/5)});
%Two points on the graph are drawn.
\coordinate (left_endpoint) at ({-4*(2/5)},{-4*(2/5)});
\draw[fill] (left_endpoint) circle [radius=1.5pt];
\coordinate (right_endpoint) at ({12*(2/5)},{-4*(2/5)});
\draw[fill] (right_endpoint) circle [radius=1.5pt];
%The graph for the area function "starting at 2" is drawn. It is defined on 6 "pieces" of the
%domain of f.
%\draw[color=blue] plot [domain=-4:0] ({(2/5)*(\x)}, {(2/5)*((\x)^2 + 4*x - 4)});
%\draw[color=blue] plot [domain=0:2] ({(2/5)*(\x)}, {(2/5)*(-(\x)^2 + 4*x - 4)});
%\draw[color=blue] plot [domain=2:4] ({(2/5)*(\x)}, {(2/5)*((\x)^2 - 4*x + 4)});
%\draw[color=blue] plot [domain=4:8] ({(2/5)*(\x)}, {(2/5)*(-(\x)^2 + 12*x - 28)});
%\draw[color=blue] plot [domain=8:10] ({(2/5)*(\x)}, {(2/5)*((\x)^2 - 20*x + 100)});
%\draw[color=blue] plot [domain=10:12] ({(2/5)*(\x)}, {(2/5)*(-(\x)^2 + 20*x - 100)});
%Tick marks are drawn along the y-axis.
\draw ($(0,{-4*(2/5)}) +(-2pt,0)$) -- ($(0,{-4*(2/5)}) +(2pt,0)$);
\path node[anchor=east, inner sep=0, font=\footnotesize] at ($(0,{-4*(2/5)}) +(-2pt,0) +(-0.15,0)$){$-4$};
\draw ($(0,{4*(2/5)}) +(-2pt,0)$) -- ($(0,{4*(2/5)}) +(2pt,0)$);
\path node[anchor=east, inner sep=0, font=\footnotesize] at ($(0,{4*(2/5)}) +(-2pt,0) +(-0.15,0)$){4};
%The axes are drawn.
\draw[latex-latex] ($(0,{-4*(2/5)}) +(0pt,-12.5pt)$) -- ($(0,{4*(2/5)}) +(0pt,12.5pt)$) node[above right]{$y$};
\draw[latex-latex] ($({-4*(2/5)},0) +(-12.5pt,0pt)$) -- ($({12*(2/5)},0) +(12.5pt,0pt)$) node[below right]{$x$};
\end{tikzpicture}
\end{document}
答案1
不確定這是否是您所期望的,但修復x
了\x
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
%A piecewise linear function is drawn over the interval [-4, 12]. (The figure is magnified by 2/5.)
\draw ({-4*(2/5)},{-4*(2/5)}) -- (0,{4*(2/5)}) -- ({2*(2/5)},0) -- ({4*(2/5)},{4*(2/5)}) -- ({8*(2/5)},{-4*(2/5)})
-- ({10*(2/5)},0) -- ({12*(2/5)},{-4*(2/5)});
%Two points on the graph are drawn.
\coordinate (left_endpoint) at ({-4*(2/5)},{-4*(2/5)});
\draw[fill] (left_endpoint) circle [radius=1.5pt];
\coordinate (right_endpoint) at ({12*(2/5)},{-4*(2/5)});
\draw[fill] (right_endpoint) circle [radius=1.5pt];
%The graph for the area function "starting at 2" is drawn. It is defined on 6 "pieces" of the
%domain of f.
\draw[color=blue] plot [domain=-4:0] ({(2/5)*(\x)}, {(2/5)*((\x)^2 + 4*\x - 4)});
\draw[color=blue] plot [domain=0:2] ({(2/5)*(\x)}, {(2/5)*(-(\x)^2 + 4*\x - 4)});
\draw[color=blue] plot [domain=2:4] ({(2/5)*(\x)}, {(2/5)*((\x)^2 - 4*\x + 4)});
\draw[color=blue] plot [domain=4:8] ({(2/5)*(\x)}, {(2/5)*(-(\x)^2 + 12*\x - 28)});
\draw[color=blue] plot [domain=8:10] ({(2/5)*(\x)}, {(2/5)*((\x)^2 - 20*\x + 100)});
\draw[color=blue] plot [domain=10:12] ({(2/5)*(\x)}, {(2/5)*(-(\x)^2 + 20*\x - 100)});
%Tick marks are drawn along the y-axis.
\draw ($(0,{-4*(2/5)}) +(-2pt,0)$) -- ($(0,{-4*(2/5)}) +(2pt,0)$);
\path node[anchor=east, inner sep=0, font=\footnotesize] at ($(0,{-4*(2/5)}) +(-2pt,0) +(-0.15,0)$){$-4$};
\draw ($(0,{4*(2/5)}) +(-2pt,0)$) -- ($(0,{4*(2/5)}) +(2pt,0)$);
\path node[anchor=east, inner sep=0, font=\footnotesize] at ($(0,{4*(2/5)}) +(-2pt,0) +(-0.15,0)$){4};
%The axes are drawn.
\draw[latex-latex] ($(0,{-4*(2/5)}) +(0pt,-12.5pt)$) -- ($(0,{4*(2/5)}) +(0pt,12.5pt)$) node[above right]{$y$};
\draw[latex-latex] ($({-4*(2/5)},0) +(-12.5pt,0pt)$) -- ($({12*(2/5)},0) +(12.5pt,0pt)$) node[below right]{$x$};
\end{tikzpicture}
\end{document}