问题:

问题:

抱歉问了这么多问题,不过我在创建功能线的代码上还是遇到了一些问题。我在这里修复了一些小错误功能线错误。但是,代码仍然没有产生我期望的结果

以下面的代码为例

    \begin{functionallines}[
    extra x tick labels={$\mathrm{e}^{-3/2}$},
    xtick={-0.5,0,1}]{0.223}{-0.5:1}
        \functionalline[f(x)=2\ln(x)+3]{2*ln(x)+3}{2}{0.223}
        \functionalline[]{1}{3}{}
    \end{functionallines}

结果如下

在此处输入图片描述

然而,我原本期望的结果是这样的:

在此处输入图片描述

我怀疑不匹配是因为函数没有为值定义< 0,所以没有绘制。有没有办法解决这个问题以正确显示对数?

在上图中,x表示函数在该特定点未定义,而0表示函数在该点为零。

我想知道为什么第一幅图显示不正确?特别是对于x = e^{-3/2}我本应看到 a ,0因为这里的函数为零,而对于x = 0我本应看到 a x

问题:

  • 有没有更好的方法来在函数为零和未定义之间切换?手动或自动。(也许是一个可选参数,用于将 x 标记插入到行中?)
  • 有没有办法在比定义函数更大的域中显示函数?

平均能量损失

\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath}

\pgfplotsset{
    shift down/.style={
         y filter/.code={\pgfmathparse{\pgfmathresult*(#1)}}
    },
    shift down/.default=1,
    every axis plot post/.style={restrict y to domain=0.5:inf},
    positive/.style={
        no markers,
        red
    },
    negative/.style={
        no markers,
        blue
    },
    /tikz/function label/.style={
        anchor=east
    },
    step functionallinenumber/.code={
        \stepcounter{functionallinenumber}
    },
    title entries/.initial={}
}

\makeatletter
\newcommand\functionalline[4][\@empty]{
    \edef\plots{
        \noexpand\addplot [negative, shift down=#3, forget plot] {#2<0};
        \noexpand\addplot [positive, shift down=#3, forget plot] {#2>0};
    }
    \plots
    \node at (axis cs:\pgfkeysvalueof{/pgfplots/xmin},#3) [function label] {%
        \ifx#1\@empty%
            $#2$%
        \else%
            $#1$%
        \fi
    };

    \pgfplotsinvokeforeach {#4} {
       \node at (axis cs:##1,#3) [
        fill=white,
        inner sep=1pt,
        declare function={x=##1;} % Set 'x' to current position
    ] {%
    \pgfkeys{/pgf/fpu}% Use the fpu library, because it doesn't throw an error for divide by zero, but sets result to +/- inf
    \pgfmathparse{#2}%
    \pgfmathfloatifflags{\pgfmathresult}{0}{0}{x}% Check whether result is zero. The \hspace is necessary because of a bug in the fpu library. (Update 11 June 2012: Doesn't seem to be the case anymore, the \hspace can be removed)
    \pgfkeys{/pgf/fpu=false}%
    };
    }   
}

\newenvironment{functionallines}[3][]{
    \begin{tikzpicture}
    \begin{axis}[        
        extra x ticks = {#2},
        grid=none,
        xticklabel pos=right,
        hide y axis,
        x axis line style={draw=none},
        every tick label/.style={
            anchor=base,
            yshift=1ex,
            gray!50
        },
        every extra x tick/.style={
            every tick label/.style={
                anchor=base,
                yshift=1ex,
                inner xsep=0pt,
                fill=white,
                text=black
            }
        },
        extra x tick style={grid=major},
        xtick pos=right,
        major tick length=0pt,
        enlarge x limits=false,
        enlarge y limits={abs=0.75},
        domain=#3,
        samples=100,
        y = -0.5cm,
        clip=false,
        #1
    ]
}{
    \coordinate (bottom right) at (rel axis cs:1,0);
    \coordinate (top right) at (rel axis cs:1,1);
    \end{axis}
    \draw [-latex] (top right-|current bounding box.west) -- (top right) node [right] {$x$};
    \draw (bottom right) -- (bottom right-|current bounding box.west);
    \end{tikzpicture}
}

\begin{document}

    \begin{center}
        \begin{functionallines}[
        extra x tick labels={$\mathrm{e}^{-3/2}$},
        xtick={-0.5,0,1}]{0.223}{-0.5:1}
            \functionalline[f(x)=2\ln(x)+3]{2*ln(x)+3}{2}{0.223}
        \end{functionallines}
    \end{center}

\hspace{1cm}

    \begin{center}
        \begin{functionallines}[
        extra x tick labels={$e^{-1/2}$},
        xtick={-1,0,1}]{0.606}{-1:1.5}]
            \functionalline{x}{1}{0}
            \functionalline[2\ln+1]{2*ln(x)+1}{2}{0.6065}
            \functionalline[f'(x) = x(2 \ln x + 1)]{2*x*ln(x)+x}{3.5}{0,0.6065}
        \end{functionallines}
    \end{center}

\end{document}

相关内容