我如何绘制此函数的图形?

我如何绘制此函数的图形?

我需要绘制函数f(x) = -5/16x^4 + 3/4x^3 + 1,但我不知道该怎么做。

我已经做了一些与我需要的类似的事情:

\draw[thick,color=blue] plot[samples=50, domain=-1.4:1.8] (\x,{(\x)^3-(\x)^2+1}) node[right] {$f(x) = x^3 - x^2 + 1$};

但它对处理以下函数没有帮助。这是另一个程序绘制的图。

在此处输入图片描述

答案1

  • 代码片段中提到的函数与问题中图片中显示的函数不同。我在下面考虑了第一个,但更改它并不困难。
  • 在下面的 MWE 中,我使用包pgfdplots版本 v1.14。
  • x选取最小值,使得函数方程能够拟合成图。

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
ticklabel style={fill=white, font=\footnotesize},
xmin=-5, xmax=3, xlabel={$x$}, xtick={-5,...,3},
ymin=-5, ymax=3, ylabel={$y$}, ytick={-5,...,3},
grid,
 axis lines=middle
]
\addplot[blue, very thick, samples=50, domain=-2:1.8] {(x)^3 -(x)^2 + 1};
\node[below right, fill=white, text=blue] at (-4,3) {$f(x) = x^3 - x^2 + 1$};
\end{axis}
\end{tikzpicture}
\end{document}

![在此处输入图片描述

如果您想要第二个方程,则适当更改线条\addplot ...\node ...。您还可以将轴放在顶部并放大图形宽度和函数域,如下所示:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=88mm,
ticklabel style={fill=white, inner xsep=1pt, font=\footnotesize},
xmin=-5, xmax=4, xlabel={$x$}, xtick={-5,...,4},
ymin=-5, ymax=3, ylabel={$y$}, ytick={-5,...,3},
set layers = axis on top,
axis lines = middle,
grid=both,
]
\addplot[blue, very thick, samples=50, domain=-2:4] {-5*(x^4)/16 + 3*(x^3)/4 + 1};
\node[below right, inner xsep=0pt, fill=white, text=blue] at (-5,3) 
    {$f(x) = -\frac{5}{16}x^4 + \frac{3}{4}x^3 + 1$};
\end{axis}
\end{tikzpicture}
\end{document}

并且图表将变成:

![在此处输入图片描述

相关内容