PGFplot이 내 표현을 인식하지 못하는 이유는 무엇입니까?

PGFplot이 내 표현을 인식하지 못하는 이유는 무엇입니까?

pgfplots를 사용하여 두 개의 이차 방정식을 그래프로 표시하고 싶습니다. 첫 번째 방정식은 잘 작동하지만 두 번째 방정식을 추가하면 다음과 같은 오류 메시지가 나타납니다.

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};

그러면 효과가 있을 것입니다.

관련 정보