我需要用和的值绘制这个多变量函数\alpha, \beta
。R
[![在此处输入图像描述][1]][1] 其他用户帮助我做了一些非常类似的事情,但现在我的代码出现了问题:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={$n$},
ylabel={$R(n)$},
axis lines=center,
declare function={t(\n,\a,\b,\R)=(\n*\a*\b)/(\a+\b*\n)*%
(((\R*\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1)-((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*%
(\b*(\n-1)+1))*pow((\R*(\n*\b+\a-1)*%
pow((\n*\b+\a),-1)),\b*(\n-1)+1))/(\a+\b*(\n-1)))*%
pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1)),-\a-\b*(\n-1)+%
(pow((\R*(\n*\b+\a-1)*(\n*\b+\a)),1-\a))/(\a-1)*%
((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*(\b*(\n-1)+1)));},
domain=1:8,no marks,samples=20,smooth]
\addplot[color=black, domain=1:8]{t(n,2.5,0.5,3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
因为我的输出是这样的:
[![在此处输入图片描述][2]][2]
预期是这样的:
[![在此处输入图片描述][3]][3]
有人能帮我找出错误吗?并且:我怎样才能减小轴上的数字大小?我怎样才能将 y 标签移到 y 轴的左侧,将 x 标签移到 x 轴的下方?(就像预期的输出一样)
编辑:
感谢用户薛定谔的猫,我解决了错误并发现了一个新的错误,我的代码现在是:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={signal},
ylabel={equilibrium bid},
axis lines=left,
declare function={H(\x,\n,\a,\b,\R)=pow(\R,\b*(\n-1)+1)*%
pow(\n*\b+\a-1,\b*(\n-1))*pow(\n*\b+\a,-\b*(\n-1))*pow(\x,-\b*(\n-1))+%
(\n*\b+\a)/(\n*\b+\a-1)*\x*(((\n-1)*\b)/((\n-1)*\b+1))*%
(1-pow(\R,\b*(\n-1)+1)*pow(\n*\b+\a-1,\b*(\n-1)+1)*%
pow(\n*\b+\a,-\b*(\n-1)-1)*%
pow(\x,-\b*(\n-1)-1));},
domain=2.1:2.7,no marks,samples=11,smooth]
\addplot[color=black]{H(x,2,2.5,0.5,3)};
\addplot[color=black, dashed, domain=2.25:2.7]{H(x,3,2.5,0.5,3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\centering
{Figure 1. Equilibrium bid of Example 1 with $\alpha=2.5$, $\beta=.5$, $r=3$ for $n=2$ (solid line) and $n=3$ (dashed line).}
\clearpage
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={bidders},
ylabel={revenue},
axis lines=left,
declare function={tt(\n,\a,\b,\R)=(\n*\a*\b)/(\a+\b*\n)*%
(((\R*\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1)-((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*%
(\b*(\n-1)+1))*pow((\R*(\n*\b+\a-1)*%
pow((\n*\b+\a),-1)),\b*(\n-1)+1))/(\a+\b*(\n-1)))*%
pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1),-\a-\b*(\n-1))+% <-
(pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1),1-\a))/(\a-1)*
((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*(\b*(\n-1)+1)));
},
domain=1:8,no marks,samples=20,smooth]
\addplot[color=black, domain=1:8,variable=\n]{tt(n,2.5,0.5,3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
但现在输出很少,为什么 y 轴上显示两次 0.17、0.18 和 0.19?预期输出是从 0.15 到 0.19。我该如何解决这个问题?[![在此处输入图片描述][4]][4]
感谢您!!
答案1
有两个问题。首先,n
没有定义,您需要说variable=\n
(或者更简单地使用x
而不是n
)。然后您放错了)
一个
pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1)),-\a-\b*(\n-1)+%
我认为应该
pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1),-\a-\b*(\n-1))+%
至少没有更多的错误:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={$n$},
ylabel={$R(n)$},
axis lines=center,
declare function={tt(\n,\a,\b,\R)=(\n*\a*\b)/(\a+\b*\n)*%
(((\R*\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1)-((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*%
(\b*(\n-1)+1))*pow((\R*(\n*\b+\a-1)*%
pow((\n*\b+\a),-1)),\b*(\n-1)+1))/(\a+\b*(\n-1)))*%
pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1),-\a-\b*(\n-1))+% <-
(pow((\R*(\n*\b+\a-1)*(\n*\b+\a)),1-\a))/(\a-1)*%
((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*(\b*(\n-1)+1)));
},
domain=1:8,no marks,samples=20,smooth]
\addplot[color=black, domain=1:8,variable=\n]{tt(n,2.5,0.5,3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
附录:至于您的问题的编辑,添加ytick distance=0.01
,说。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={signal},
ylabel={equilibrium bid},
axis lines=left,
declare function={H(\x,\n,\a,\b,\R)=pow(\R,\b*(\n-1)+1)*%
pow(\n*\b+\a-1,\b*(\n-1))*pow(\n*\b+\a,-\b*(\n-1))*pow(\x,-\b*(\n-1))+%
(\n*\b+\a)/(\n*\b+\a-1)*\x*(((\n-1)*\b)/((\n-1)*\b+1))*%
(1-pow(\R,\b*(\n-1)+1)*pow(\n*\b+\a-1,\b*(\n-1)+1)*%
pow(\n*\b+\a,-\b*(\n-1)-1)*%
pow(\x,-\b*(\n-1)-1));},
domain=2.1:2.7,no marks,samples=11,smooth]
\addplot[color=black]{H(x,2,2.5,0.5,3)};
\addplot[color=black, dashed, domain=2.25:2.7]{H(x,3,2.5,0.5,3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\centering
{Figure 1. Equilibrium bid of Example 1 with $\alpha=2.5$, $\beta=.5$, $r=3$ for $n=2$ (solid line) and $n=3$ (dashed line).}
\clearpage
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={bidders},
ylabel={revenue},
axis lines=left,
declare function={tt(\n,\a,\b,\R)=(\n*\a*\b)/(\a+\b*\n)*%
(((\R*\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1)-((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*%
(\b*(\n-1)+1))*pow((\R*(\n*\b+\a-1)*%
pow((\n*\b+\a),-1)),\b*(\n-1)+1))/(\a+\b*(\n-1)))*%
pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1),-\a-\b*(\n-1))+% <-
(pow(\R*(\n*\b+\a-1)*pow((\n*\b+\a),-1),1-\a))/(\a-1)*
((\a+\b*\n)*\b*(\n-1))/((\a+\b*\n-1)*(\b*(\n-1)+1)));
},
domain=1:8,no marks,samples=20,smooth,ytick distance=0.01]
\addplot[color=black, domain=1:8,variable=\n]{tt(n,2.5,0.5,3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}