这是我的代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm,y=1cm]
\draw[->,color=black] (-0.5,0) -- (3.5,0);
\draw[->,color=black] (0,-.5) -- (0,5);
\draw[very thick, smooth,samples=100,domain=0:3] plot(\x,{1/(\x-1)^(2/3)});
\end{tikzpicture}
\end{document}
这使
! Package PGF Math Error: I cannot calculate the logarithm of `-1.0' (in '{1/(0
-1)^(2/3)}').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.7 ...s=100,domain=0:3] plot(\x,{1/(\x-1)^(2/3)})
;
?
编辑
我想要一些类似于下图的东西(阴影区域不是必需的):
答案1
使用 tkz-fct(tikz+ gnuplot + 我的软件包中的一些宏),您可以得到准确的图形。我同意,如果您想要基于 tikz 的东西,绘制函数图形的更好工具是 pgfplots。但是对于一些非常复杂的函数,您需要使用 pgfplots + gnuplot 或类似的东西...(pgfplots 可以使用 guplot)。对于 x=1 中的问题,Herbert 的想法很好,首先^2
然后1./3
。但是对于类似的东西,^(3/5)
您需要分割您的域。最后的解释:使用 gnuplot 可以获得功率**
,您需要写入1./3
以用实数除以。
\documentclass{article}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}
% macro from tkz-fct
\tkzInit[xmin=-.5,xmax=3.5,ymin=-.5,ymax=5]
\tkzDrawXY[noticks]
% part with gnuplot
\tkzFct[domain = 0:3]{(1/(x-1)**2)**(1./3)}
\tkzVLine[style = dashed,
line width = .6pt]{1}
\tkzDrawArea[color=lightgray, domain =0:0.8,draw=black]% no need to rewrite the function
% the macro uses the last function.
\tkzDrawArea[color=lightgray, domain =1.3:3,draw=black]
% \tkzDefPointByFct(.8) no need here but useful if you want a point of the curve
% part with tikz
\node[left] at (0,1) {1};
\node[below] at (1,-0.5) {1};
\node[below] at (3,0) {3};
\end{tikzpicture}
\end{document}
答案2
它需要重写函数以便y = 1/(x-1)^2^(1/3)
像下面这样绘制它:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[smooth,xmin=0,xmax=3,ymin=0,ymax=2.4,axis x line=bottom,axis y line=left]
\addplot[thick,red,domain=0:3] {1/(x-1)^2^(1/3)};
\addplot[thin,dotted] coordinates {(1,0) (1,2.4)};
\end{axis}
\end{tikzpicture}
\end{document}
...这:
答案3
运行xelatex
或pdflatex --shell-escape
\documentclass{article}
%\usepackage[pdf]{pstricks}% for `pdflatex --shell-escape`
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-1,-1)(3.5,3.5)
\psaxes{->}(0,0)(3,3)[$x$,-90][$y$,0]
\psplot[algebraic,plotpoints=1000,yMaxValue=3,
linewidth=1.5pt,linecolor=red]{0}{3}{1/((x-1)^2)^(1/3)}
\psline[linestyle=dashed](1,0)(1,3)
\end{pspicture}
\hspace{5mm}
\begin{pspicture}(-1,-1)(3.5,3.5)
\pscustom[fillstyle=solid,fillcolor=blue!20,linestyle=none]{
\psplot[algebraic,plotpoints=1000,yMaxValue=3]{0}{0.8}{1/((x-1)^2)^(1/3)}
\psplot[algebraic,plotpoints=1000,yMaxValue=3]{1.2}{3}{1/((x-1)^2)^(1/3)}
\psline(*3 {1/((x-1)^2)^(1/3)})(3,0)(0,0)}
\psline[linewidth=0.36,linecolor=white](1,0)(1,3)
\psaxes{->}(0,0)(3,3)[$x$,-90][$y$,0]
\psplot[algebraic,plotpoints=1000,yMaxValue=3,
linewidth=1.5pt,linecolor=red]{0}{3}{1/((x-1)^2)^(1/3)}
\psline[linestyle=dashed](1,0)(1,3)
\end{pspicture}
\end{document}
答案4
对于曲线下的填充,您可以用不同的填充颜色绘制两次。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmax=3.5,xmin=0,ymin=0,ymax=7,
xtick={1,3},ytick=1,
axis x line=bottom,
axis y line=left,
width=4cm,height=5cm]
\addplot+[draw=black,fill=gray,domain=0:3,no marks,samples=50] {(1/(x-1)^2)^(1/3)} \closedcycle;
\addplot+[draw=black,fill=white,domain=0.8:1.4,no marks,samples=50] {(1/(x-1)^2)^(1/3)} \closedcycle;
\draw (axis cs:1,0) -- (axis cs:1,7);
\end{axis}
\end{tikzpicture}
\end{document}