绘制 y=x^(-0.5)

绘制 y=x^(-0.5)

我怎样绘制 y=x^(-0.5)?

\documentclass[border=2pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

                \draw[->] (0,0) -- (6.2,0) node[right] {$Q$};
                \draw[->] (0,0) -- (0,6.2) node[above] {$P$};
                \draw[thick,purple,smooth] plot (\x,{(2)^(0.5)*(\x)^(-0.5)});
                \draw[thick,brown,smooth] plot (\x,{(0.5)^(0.5)*(\x)^(-0.5)});

\end{tikzpicture}
\end{document}

答案1

这是一个pgfplots解决方案,但它也适用于正常情节。

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[xmax=3]
    \draw[->] (0,0) -- (6.2,0) node[right] {$Q$};
    \draw[->] (0,0) -- (0,6.2) node[above] {$P$};
    \addplot[domain=0.001:3,samples=201,purple,thick,smooth]{2^0.5*x^-0.5};
    \addplot[domain=0.001:3,samples=201,brown,thick,smooth]{0.5^0.5*x^-0.5};    
      %          \draw[thick,purple,smooth] plot (\x,{(2)^(0.5)*(\x)^-0.5});
      %          \draw[thick,brown,smooth] plot (\x,{(0.5)^(0.5)*(\x)^-0.5});
  \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您必须添加有效的,domain因为默认情况下(-5,5)没有x^0.5为负值定义。

\documentclass[border=2pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

                \draw[->] (0,0) -- (6.2,0) node[right] {$Q$};
                \draw[->] (0,0) -- (0,6.2) node[above] {$P$};
                \draw[thick,purple,smooth] plot [domain=0:5] (\x,{(2)^(0.5)*(\x)^(-0.5)});
                \draw[thick,brown,smooth] plot [domain=0:5] (\x,{(0.5)^(0.5)*(\x)^(-0.5)});

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

你可以让你的公式更简单一点,我建议为了这:

% arara: pdflatex

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[%
        ,xlabel=$Q$
        ,ylabel=$P$
        ,xmin=0,xmax=6.2
        ,ymin=0,ymax=6.2
        ,axis x line=bottom
        ,axis y line=left
        ,every axis x label/.style={at={(current axis.right of origin)},anchor=west}
        ,every axis y label/.style={at={(current axis.north west)},anchor=south}
        ]
    \addplot[%
        ,samples at={0.05,0.1,...,6}
        ,smooth
        ,thick
        ,purple
        ] {sqrt(2/x)};
    \addplot[%
        ,samples at={0.05,0.1,...,6}
        ,smooth
        ,thick
        ,brown
        ] {sqrt(0.5/x)};
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容