我绘制这些图表时犯了哪些错误?

我绘制这些图表时犯了哪些错误?

这是我的代码:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{width=5cm,compat=1.9}
\usepgfplotslibrary{external}
\tikzexternalize

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = box,
    xlabel = $x$,
    ylabel = {$f(x)$},
]
%Below the red parabola is defined
\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
    ]
{x^2 + 2*y^2 - 5 - 44/100};
\addlegendentry{$x^2 + 2*y^2 - 5 - 44/100$}
%Here the blue parabloa is defined
\addplot [
    domain=-10:10, 
    samples=100, 
    color=blue,
    ]
    {x^2 - x*y + y};
\addlegendentry{x^2 - x*y + y}

\end{axis}
\end{tikzpicture}
\end{document}

我想绘制这些函数的图形:x^2 + 2y^2 - 5 - 44/100 = 0 且 x^2 - xy + y = 0。我的错误在哪里?

答案1

您需要addplot3为此并减少样本数量以不超过 TeX 内存。您也可以使用meshsurf并且宽度太小我使用了width=12cm

\documentclass[11pt,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{width=12cm,compat=1.9}
\usepgfplotslibrary{external}
\tikzexternalize

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = box,
    xlabel = $x$,
    ylabel = {$f(x)$},
]
% Below the red parabola is defined
\addplot3 [
    domain=-10:10, 
    surf,
    %samples=50, 
    color=red,
    ]
{x^2 + 2*y^2 - 5 - 44/100};
\addlegendentry{$x^2 + 2y^2 - 5.44$}
% Here the blue parabloa is defined
\addplot3 [
    domain=-10:10, 
    %samples=50, 
    surf,
    color=blue,
    ]
    {x^2 - x*y + y};
\addlegendentry{$x^2 - xy + y$}
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容