仅使用 TikZ 绘制分段函数,其中每段都是抛物线

仅使用 TikZ 绘制分段函数,其中每段都是抛物线

f我有一个在闭区间上定义的分段线性函数的代码,[-4, 12]. 我通过缩放图像2/5

在同一张图上,我想绘制另一个分段函数,g表示$\int_{2}^{x} f(t) \, dt$任意数字$-4 \leq x \leq 12$。它涉及在 的定义域的六个不同“部分”上绘制抛物线f。我在代码中提供了这些命令,前面带有%。执行任何这些命令都会收到错误消息。

我知道fg可以很容易地使用 来绘制。但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}

相关内容