%%%------------------------------------------------------------------------------------------------------------ \begin{tikzpicture} \begin{scope}[yscale=0.2,xscale=0.8] \draw[-,very thick,ublue,domain=-4.2:3.5,samples=100] plot (\x,{ - 1/14 * (\x + 4) * (\x + 1) * (\x - 1) * (\x - 3)}); { \draw[-,very thick,ugreen,domain=-3.8:3.0,samples=100] plot (\x,{ - 1/14 * (4*\x*\x*\x + 3*\x*\x - 26*\x - 1)}); } \draw[->,thick] (-6,0) -- (5,0); \draw[->,thick] (-5,-4) -- (-5,5); \draw [<-] (-2.5,4) -- (-2,5) node [pos=1,right,inner sep=2pt] {\footnotesize{答案$\tilde{\textbf{y}}_i$}}; { \draw [<-] (-3,-3) -- (-2.5,-2) node [pos=0,left,inner sep=2pt] {\footnotesize{预测$\textbf{y}_i$}};} { \draw [<-] (2.3,1) -- (3.3,2) node [pos=1,right,inner sep=2pt] {\footnotesize{偏差$|\tilde{\textbf{y}}_i - \textbf{y}_i|$}}; \foreach \x in {-3.8,-3.7,...,3.0}{ \pgfmathsetmacro{\p}{- 1/14 * (\x + 4) * (\x + 1) * (\x - 1) * (\x - 3)}; \pgfmathsetmacro{\q}{- 1/14 * (4*\x*\x*\x + 3*\x*\x - 26*\x - 1)}; \draw [-] (\x,\p) -- (\x, \q); } } \end{scope} \end{tikzpicture} %%%------------------------------------------------------------------------------------------------------------