通过点绘制函数

通过点绘制函数

我想:

  • 绘制函数(-0.06*x^(3))+(0.29*x^(2))-(0.65*x)+2

编辑:主要目标是通过点 (-1,3)、(4,0)、(6,5) 和 (0,2) 绘制函数

  • 保持 1:1 的比例

关于绘制函数:

在 Geogebra 上,该函数如下所示:在此处输入图片描述

在 Latex 上,该函数如下所示:在此处输入图片描述

函数必须经过点 (4,0) 和 (6,-5)。我在互联网上搜索并增加了采样,但问题并没有解决。我收到了编译器的错误,但它没有提供太多信息(可能是由于 overleaf?它不知道“关键 tikz 绘制蓝色”)。

关于保持 1:1 的比例:

我在网上搜索并尝试了几种解决方案,但没有定论

主文本:

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}

%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}%  permet de dessiner des figures, des graphiques
\usepackage{pgfplots}
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre

%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)

\usepackage{xcolor}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_fig}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{adjustbox}{width={15cm},totalheight={15cm},keepaspectratio}
\begin{tikzpicture}[font={\sansmath\sffamily},thick, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm]

%%%%%%%%%%%%%%%%%% Data Table %%%%%%%%%%%%%%%%%%
\begin{axis}[%
    width=15cm,
    xlabel=$x$,ylabel=$y$,
    xmin=-10, xmax=10,
    ymin=-8,ymax=8,
    %minor xtick={-10,-9,...,8},
    %minor ytick={-8,-7,...,8},
    domain=-10:10,
    minor tick num=1,
    grid=both, 
    axis lines = middle,
    enlargelimits=false,
    thick,
    smooth,
    samples=5000,
           ]%
           \draw[color=blue, opacity=0.8] (axis cs:-9,2) coordinate node [circle, fill=blue, draw=blue, scale=.5] {} -- (axis cs:-2,5) coordinate node [circle, fill=white, draw=blue, scale=.5] {};
           \addplot[%
                color=blue,
                opacity=0.8,
                domain=-1:6,
                ]%
                {(-0.06*x^(3))+(0.29*x^(2))-(0.65*x)+2}
                node [circle, fill=white, draw=blue, scale=.5, pos=0] {}
                node [above right, pos=0.3] {g(x)}
                node [circle, fill=blue, draw blue, scale=.5, pos=1] {};
\end{axis}

\end{tikzpicture}
\end{adjustbox}
\end{document}

答案1

就这样!尽量不要在绘图中使用不必要的样本。使用就samples=500足够了。希望它能如你所愿!

\documentclass[border=10pt]{standalone}

%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}%  permet de dessiner des figures, des graphiques
\usepackage{pgfplots}
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre

%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)

\usepackage{xcolor}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_fig}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{adjustbox}{width={15cm},totalheight={15cm},keepaspectratio}
\begin{tikzpicture}[font={\sansmath\sffamily},thick, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm]

%%%%%%%%%%%%%%%%%% Data Table %%%%%%%%%%%%%%%%%%
\begin{axis}[%
    axis equal,
    width=15cm,
    xlabel=$x$,ylabel=$y$,
    xmin=-10, xmax=10,
    ymin=-8,ymax=8,
    %minor xtick={-10,-9,...,8},
    %minor ytick={-8,-7,...,8},
    domain=-10:10,
    minor tick num=1,
    grid=both, 
    axis lines = middle,
    enlargelimits=false,
    thick,
    smooth,
    samples=500,
           ]%
           \draw[color=blue, opacity=0.8] (axis cs:-9,2) coordinate node [circle, fill=blue, draw=blue, scale=.5] {} -- (axis cs:-2,5) coordinate node [circle, fill=white, draw=blue, scale=.5] {};
           \addplot[%
                color=blue,
                opacity=0.8,
                domain=-1:6,
                ]%
                {-13/210*x^3+2/7*x^2-137/210*x+2}
                node [circle, fill=white, draw=blue, scale=.5, pos=0] {}
                node [above right, pos=0.3] {g(x)}
                node [circle, fill=blue, draw=blue, scale=.5, pos=1] {};
\end{axis}

\end{tikzpicture}
\end{adjustbox}
\end{document}

例子

答案2

因此,要通过点绘制任何“函数”,只需通过坐标画一条平滑的线即可

在此处输入图片描述

来源:https://tex.stackexchange.com/a/490375/206952

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}

%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}%  permet de dessiner des figures, des graphiques
\usepackage{pgfplots}
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre

%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)

\usepackage{xcolor}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_fig}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{adjustbox}{width={15cm},totalheight={15cm},keepaspectratio}
\begin{tikzpicture}[font={\sansmath\sffamily},thick, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm]

%%%%%%%%%%%%%%%%%% Data Table %%%%%%%%%%%%%%%%%%
\begin{axis}[%
    width=15cm,
    xlabel=$x$,ylabel=$y$,
    xmin=-10, xmax=10,
    ymin=-6,ymax=6,
    unit vector ratio=1 1 1,
    domain=-10:10,
    %minor xtick={-10,...,8},
    %minor ytick={-8,...,8},
    %minor tick num=1,
    grid=both, 
    axis lines = middle,
    enlargelimits=false,
    thick,
    smooth,
    samples=100,
           ]%
           \draw[color=blue, opacity=0.8] (axis cs:-9,2) coordinate node [circle, fill=blue, draw=blue, scale=.5] {} -- (axis cs:-2,5) coordinate node [circle, fill=white, draw=blue, scale=.5] {};
           \addplot[%
                color=blue,
                opacity=0.8,
                domain=-1:6,
                smooth,
                ]%
                coordinates {(-1,3) (0,2) (4,0) (6,-5)}
                node [circle, fill=white, draw=blue, scale=.5, pos=0] {}
                node [above right, pos=0.3] {g(x)}
                node [circle, fill=blue, draw=blue, scale=.5, pos=1] {};
\end{axis}

\end{tikzpicture}
\end{adjustbox}
\end{document}

希望它能帮助其他人。

相关内容