我想绘制 Gamma 函数及其倒数,但我是 Latex 新手。请帮帮我!
答案1
Gamma 函数未定义为消极的整数。我在这里使用的原因\multido
。使用 运行示例xelatex
:
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\psset{yunit=0.75}
\begin{pspicture}(-5,-5)(5,5)
\psaxes{->}(0,0)(-4.5,-4.5)(4.5,4.5)
\multido{\rA=-3.999+1.000}{8}{%
\psplot[linewidth=1.5pt,linecolor=red,
plotpoints=500,algebraic]{\rA}{\rA\space 0.9999 add}{ 1/GAMMA(x) }}
\end{pspicture}
\end{document}
答案2
这里还有另外两种可能性:sagetex
使用 Sage 输出(最简单)或sagetex
使用 pgfplots(更复杂)。您需要在计算机上安装 Sage 或使用思杰云以避免 Sage 出现在您的计算机上。
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{pgfplots}
\usepackage{sagetex}
\usetikzlibrary{spy}
\usetikzlibrary{backgrounds}
\usetikzlibrary{decorations}
\pagestyle{empty}
\begin{document}
The easiest way to plot with Sage using its output.
\begin{sagesilent}
from sage.functions.other import gamma1
P = plot(1/gamma1(x),(x,-4.25,4.25),ymin=-4)
Q = text("1/$\Gamma(x)$", (4,1), alpha=0.3, fontsize='large', fontweight='extra bold', color='blue')
\end{sagesilent}
\begin{center}
\sageplot[width=4in]{P+Q}
\end{center}
If you want output plotted with pgfplots then more work is required.
\begin{sagesilent}
LowerX = -4.25
UpperX = 4.25
LowerY = -4.25
UpperY = 4.25
step = .01
Scale = 1.0
xscale=1.0
yscale=1.0
output = r""
output += r"\begin{tikzpicture}"
output += r"[line cap=round,line join=round,x=8.75cm,y=8cm]"
output += r"\begin{axis}["
output += r"grid = none,"
output += r"minor tick num=4,"
output += r"every major grid/.style={Red!30, opacity=1.0},"
output += r"every minor grid/.style={ForestGreen!30, opacity=1.0},"
output += r"height= %f\textwidth,"%(yscale)
output += r"width = %f\textwidth,"%(xscale)
output += r"thick,"
output += r"black,"
output += r"axis lines=center,"
output += r"domain=%f:%f,"%(LowerX,UpperX)
output += r"line join=bevel,"
output += r"xmin=%f,xmax=%f,ymin= %f,ymax=%f,"%(LowerX,UpperX,LowerY, UpperY)
#output += r"xticklabels=\empty,"
#output += r"yticklabels=\empty,"
output += r"major tick length=5pt,"
output += r"minor tick length=0pt,"
output += r"major x tick style={black,very thick},"
output += r"major y tick style={black,very thick},"
output += r"minor x tick style={black,thin},"
output += r"minor y tick style={black,thin},"
#output += r"xtick=\empty,"
#output += r"ytick=\empty"
output += r"]"
##FUNCTION 1
from sage.functions.other import gamma1
P = plot(1/gamma1(x),(x,-4.25,4.25),ymin=-4)
t1 = var('t1')
x1_coords = srange(LowerX,UpperX,step)
y1_coords = [(1/gamma1(t1)).n(digits=6) for t1 in x1_coords]
output += r"\addplot[thin, NavyBlue, unbounded coords=jump] coordinates {"
for i in range(0,len(x1_coords)):
if (y1_coords[i])<LowerY or (y1_coords[i])>UpperY:
output += r"(%f,inf) "%(x1_coords[i])
else:
output += r"(%f,%f) "%(x1_coords[i],y1_coords[i])
output += r"};"
output += r"\addlegendentry{$\frac{1}{\Gamma(x)}$}"
##### COMMENT OUT A LINE OF SAGESILENT BY STARTING WITH #
output += r"\end{axis}"
output += r"\end{tikzpicture}"
\end{sagesilent}
\begin{center}
\sagestr{output}
\end{center}
\end{document}
在 Sagemath Cloud 中输出如下:
请注意,第一个图(使用 Sage 和sagetex
)由第一个环境中的代码创建sagesilent
。gamma 函数是 Sage 代码的一部分。文档是这里。
答案3
Asymptote
版本:
// gammaplot.asy:
//
settings.tex="pdflatex";
import graph;
size(9cm,7cm);
import fontsize;defaultpen(fontsize(9pt));
texpreamble("\usepackage{lmodern}");
pen linePen=darkblue+0.9bp;
arrowbar arr=Arrow(HookHead,size=2);
real xmin=-4,xmax=4.4;
real ymin=-1.4,ymax=4.4;
xaxis(xmin,xmax,RightTicks(Step=1,step=0.5,OmitTick(0)),arr);
yaxis(ymin,ymax,LeftTicks(Step=1,step=0.5,OmitTick(0)),arr);
real f(real x){return 1/gamma(x);}
real eps=1e-5; // to avoid Floating point exception
draw(graph(f,xmin+eps,xmax,n=400),linePen,arr);
label("$1/\Gamma(x)$",(3,f(3)),plain.NE);
//
// run `asy gammaplot.asy` to get `gammaplot.pdf`
答案4
% arara: pdflatex: { shell: on }
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle,xtick={-4,...,4},ytick={-4,...,4}]
\addplot[domain=-4.1:4,red,samples=100] gnuplot {1/(gamma(x))} ;
\node at (axis cs:3.4,.75) {$1/\Gamma(x)$};
\end{axis}
\end{tikzpicture}
\end{document}