pgfplots exp(-pow(deg(x),2) 在域 0:2*pi 上

pgfplots exp(-pow(deg(x),2) 在域 0:2*pi 上

此代码向我抛出一个错误,“尺寸太大”。我不知道该如何修复。我刚刚测量了我的全局错误的来源,以下是一段简短的代码:

\begin{tikzpicture} 
\begin{axis}[axis lines=none,no markers,samples=50,grid=both]
\addplot3[mesh, domain=0:2*pi] {exp(-pow(deg(x),2))}; 
\end{axis}
\end{tikzpicture}

我需要在该域上绘制此函数。有办法吗?数学上应该这样做:$$e^{-deg(x)^2}$$(顺便说一句,我不知道 deg(**) 是什么意思?)

tikz我的全部目标是:用或绘制克莱因瓶pgfplots

答案1

我使用德语维基“克莱因瓶”的条目给出了以下结果。(此外,我还使用了 LuaLaTeX 和 PGFPlots 的 Lua 后端,它们计算结果非常快。)

% used PGFPlots v1.14
\RequirePackage{luatex85}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        % use this `compat' level or higher to use the Lua backend
        compat=1.12,
        % used equations and parameters from
        % <https://de.wikipedia.org/w/index.php?title=Kleinsche_Flasche&oldid=160519755#Beschreibung_im_3-dimensionalen_Raum>
        /pgf/declare function={
            b = 2;
            h = 6;
            r(\u) = 2 - cos(\u);
%            x(\u,\v) = b * (1 - sin(\u)) * cos(\u);
%                       + r(\u) * cos(\v) * (2 * exp( -(\u/2 - pi)^2 ) - 1);
%            y(\u,\v) = r(\u) * sin(\v);
%            z(\u,\v) = h * sin(\u)
%                       + 0.5 * r(\u) * sin(\u) * cos(\v) * exp( -(\u-3*pi/2)^2 );
        },
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
%            axis lines=none,
            % use radians as input for the trigonometric functions
            % (this avoids converting the numbers to `deg' format first)
            trig format plots=rad,
            domain=0:2*pi,
            samples=50,
            % change variables from `x' and `y' to `u' and `v'
            variable=u,
            variable y=v,
            colormap/viridis,
        ]
            \addplot3 [
%                mesh,
                % I use suf here, because it just looks better ;)
                surf,
                z buffer=sort,
                fill opacity=0.35,
            ] (
                % unfortunately these give an error ...
%                {x(u,v)},
%                {y(u,v)},
%                {z(u,v)},
                % ... so we write them directly
                {b * (1 - sin(u)) * cos(u) + r(u) * cos(v) * (2 * exp( -(u/2 - pi)^2 ) - 1)},
                {r(u) * sin(v)},
                {h * sin(u) + 0.5 * r(u) * sin(u) * cos(v) * exp( -(u - 3 * pi / 2)^2 )}
            );
        \end{axis}
    \end{tikzpicture}
\end{document}

该图显示了上述代码的结果

答案2

这就成功了。

\pgfplotsset{%
        colormap = {black}{%
            color(0cm)  = (black);%
            color(1cm) = (black)}%
    }

\begin{tikzpicture}
\def\rotation{0}

    \begin{axis}[axis lines=none, rotate around={\rotation:(current axis.origin)}]
    \addplot3[mesh, z buffer=sort,domain=0:180, domain y=0:360, samples=41, samples y=25,   point meta=x] 
        (
        {-2/15 * cos(x) * (
            3*cos(y) - 30*sin(x) 
          + 90 *cos(x)^4 * sin(x) 
          - 60 *cos(x)^6 * sin(x)  
          + 5 * cos(x)*cos(y) * sin(x))
         },
         {-1/15 * sin(x) * (3*cos(y) 
          - 3*cos(x)^2 * cos(y) 
          - 48 * cos(x)^4*cos(y) 
          + 48*cos(x)^6 *cos(y) 
          - 60 *sin(x) 
          + 5*cos(x)*cos(y)*sin(x) 
          - 5*cos(x)^3 * cos(y) *sin(x) 
          - 80*cos(x)^5 * cos(y)*sin(x) 
          + 80*cos(x)^7 * cos(y) * sin(x))
         },
        {2/15 * (3 + 5*cos(x) *sin(x))*sin(y)}      
        );
    \end{axis}
\end{tikzpicture}

相关内容