作图 $y=\dfrac{\sin(2x)}{1+cos^2(x)}$

作图 $y=\dfrac{\sin(2x)}{1+cos^2(x)}$

y=\dfrac{\sin(2x)}{1+cos^2(x)}我正在尝试使用以下语法绘制使用 tikzpicture 的图形:

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usetikzlibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
%
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style=thick,
axis line style={<->},
%
grid=major,
ymin=-1.1,ymax=1.4,
xmin=-0.4,xmax=3.4,
%ticks=none,
%xtick=\empty,
%
xlabel={\large $x$},
ylabel={\large $y$},
%ticks=none,
width=13cm,
height=12cm,
clip=false,
ylabel style={
    anchor=south,
    at={(ticklabel* cs:1.0)},
    yshift=1pt
},
xlabel style={
    anchor=west,
    at={(ticklabel* cs:1.0)},
    xshift=1pt
}
]
\draw[thick](axis cs:0,0) circle (1.2mm);
%
%
\addplot[name path=func3,thick,samples=200,domain=0:3.1,red] {sin(deg(2*x)/(1+cos(deg(x))*(cos(deg(x)))};
%\addplot[name path=func1,thick,samples=200,domain=-0.05:6.8,red] {sin(deg(2*x)};
%
%
%
%\addplot fill between[
%of = func0 and func1,
%soft clip={domain=0:0.9},
%every even segment/.style  = {gray,opacity=.3}
%];
\end{axis}
\newline
\end{tikzpicture}
\end{document}

这将生成以下输出: 电流输出

然而,Wolfram 数学给出了不同的输出: 期望输出

我花了几个小时在这上面但仍然不确定为什么 tikzpicture 给出了错误的图表。

谁能告诉我为什么会发生这种情况?

答案1

您的函数的括号位置有问题。您绘制了以下函数:

坏函数

另外,我不知道你为什么要使用,deg因为你的函数是用 定义的rad

pgf图

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usetikzlibrary{intersections}

\begin{document}
%
\begin{tikzpicture}
\begin{axis}[
trig format plots=rad,
axis lines=middle,
axis line style=thick,
axis line style={<->},
%
grid=major,
ymin=-1.1,ymax=1.4,
xmin=-0.4,xmax=3.4,
%ticks=none,
%xtick=\empty,
%
xlabel={\large $x$},
ylabel={\large $y$},
%ticks=none,
width=13cm,
height=12cm,
clip=false,
ylabel style={
    anchor=south,
    at={(ticklabel* cs:1.0)},
    yshift=1pt
},
xlabel style={
    anchor=west,
    at={(ticklabel* cs:1.0)},
    xshift=1pt
}
]
\draw[thick](axis cs:0,0) circle (1.2mm);
%
%
\addplot[name path=func3,thick,samples=200,domain=0:3.1,red] {sin(2*x)/(1+(cos((x))^2)};
%\addplot[name path=func1,thick,samples=200,domain=-0.05:6.8,red] {sin(deg(2*x)};
%
%
%
%\addplot fill between[
%of = func0 and func1,
%soft clip={domain=0:0.9},
%every even segment/.style  = {gray,opacity=.3}
%];
\end{axis}
\newline
\end{tikzpicture}
\end{document}

答案2

@SebGlav 答案的一个小变化:

  • xtick添加的是弧度位置
  • 添加了弧度标签xtick
  • axis所有图片样式均在选项中定义
  • pgfplots考虑该包的最新版本(1.18)的语法
%\documentclass[]{article}
%\usepackage[margin=0.5in]{geometry}
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    width=123mm,
    trig format plots=rad,
    axis lines=middle,
    axis line style = {thick,<->},
    axis on top,
%
    grid,
    xmin=-pi/6, xmax=pi,
    ymin=-0.8,  ymax=0.8,
    enlargelimits=0.1,
%
    xlabel = {$x$},
    ylabel = {$y$},
    label style = {anchor=north east, font=\large},
%
    xtick = {-pi/3, -pi/6,...,pi},
    xticklabels={-$\pi/3$, -$\pi/6$, 0, $\pi/6$, $\pi/3$, $\pi/2$, $2\pi/3$, $4\pi/3$, $\pi$},
    tick label style = {font=\footnotesize, fill=white, text height=1.2ex, inner sep=1pt},
%
    no marks, samples=101,
    domain = -pi/6:5*pi/3,
every axis plot post/.append style={very thick}
            ]
\addplot {sin(2*x)/(1+(cos(x))^2)};
\draw   (0,0) circle[radius=3pt];
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容