PGFplots が私の表現を認識しないのはなぜですか?

PGFplots が私の表現を認識しないのはなぜですか?

pgfplots を使用して 2 つの二次方程式をグラフ化したいと考えています。最初の方程式は正常に動作しますが、2 番目の方程式を追加すると、次のエラー メッセージが表示されます。

Package PGF Math Error: Unknown operator `x' or `x+' (in 'x^2 - 3x + 4').

PGFplots では数値の乗算がまったくできないようです。2xや などの関数もx * 2動作しないようです。私が使用しているのは次のようなものです:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{tikzpicture}
\begin{axis}[
    axis lines = center,
    xlabel = {$x$},
    ylabel = {$ y = f(x)$}
]
    \addplot[no markers, red]{x^2};
    \addplot[no markers, blue]{x^2 - 3x + 4};
\end{axis}
\end{tikzpicture}

赤いプロットは正常に動作しますが、青いプロットではコンパイル エラーが発生します。

答え1

pgfplotsスカラーと変数間の乗算は想定されていないため、式は次のようになりますx^2 - 3*x + 4

ここに画像の説明を入力してください

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = center,
    xlabel = {$x$},
    ylabel = {$y = f(x)$}
]
    \addplot[no markers, red]{x^2};
    \addplot[no markers, blue]{x^2-3*x+4};
\end{axis}
\end{tikzpicture}
\end{document}

答え2

試す:

 \addplot[no markers, blue]{x^2-3*x+4};

それはうまくいくはずです。

関連情報