複雑な方程式の方向フィールド

複雑な方程式の方向フィールド

次の微分方程式があります。微分方程式をグラフ化したいと思います dy/dx = \frac{2x}{x^4+1}。また、点を通る解もグラフ化したいと思います(1,1)。現在、次のようになっています。

\documentclass{report}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalenable

\begin{document}
\begin{tikzpicture}[declare function={f(\x)=2*\x/(\x^4+1);}]
  \begin{axis}[
    xmin=-4,xmax=4,
    ymin=-4,ymax=4,
    domain=-4:4,
    ]

    \def\xmax{4} \def\xmin{-4}
    \def\ymax{4} \def\ymin{-4}
    \def\nx{15}
    \def\ny{15}
    \def\yo{1}

    \pgfmathsetmacro{\hx}{(\xmax-\xmin)/\nx}
    \pgfmathsetmacro{\hy}{(\ymax-\ymin)/\ny}
    \foreach \i in {0,...,\nx}
    \foreach \j in {0,...,\ny}{
      \pgfmathsetmacro{\yprime}{f({\xmin+\i*\hx})}
      \addplot [blue,shift={({\xmin+\i*\hx},{\ymin+\j*\hy})}]
        (0,0)--($(0,0)!2mm!(.1,.1*\yprime)$);
    }

    \addplot [<->,red] {-1/4*pi+rad(atan(x^2))+1};
  \end{axis}
\end{tikzpicture}
\end{document}

しかし、次のエラーが引き続き発生します。

! Missing number, treated as zero.
<to be read again> 
                   {
l.30     }
          
?

もともと\pgfmathsetmacro{\yprime}{f({\xmin+\i*\hx},{\ymin+\j*\hy})}を の代わりに に したの\pgfmathsetmacro{\yprime}{f({\xmin+\i*\hx})}は、関数が \y を使用しないため、それを渡す必要がないためです。しかし、そのようにして関数定義を から に更新してもf(\x) = ...f(\x,\y) = ...プログラムはクラッシュし、次のようになります。

! Undefined control sequence.
\pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@ 
                                                  
l.32   \end{axis}
                 
?

私は以下の疑問を認識しています。私はこれらを試しましたが、どれもうまくいきませんでした。

  1. ラテックスですべての可能な解曲線を含む傾斜フィールドを描く方法
  2. 関数とその導関数をプロットする方法
  3. pgfplots による微分方程式の方向プロット

関連情報