我有一个要绘制的函数。但是,它有 10 个变体,每个变体有 5 个不同的常数。我不想简单地插入一个数字 50 次。有没有更简单的方法可以做到这一点?此外,图表看起来很奇怪。有没有其他方法pgfplots
可以生成图像,然后直接使用includegraphics
,最好是带有矢量图形的东西,这样它的质量最高。谢谢。
\documentclass[letterpaper]{article}
\usepackage{pgfplots} \pgfplotsset{width=10cm,compat=1.16}
\begin{document}
\[ y^{\prime} ( t ) = \frac{\lambda \phi ( \beta - \alpha )}{t \left[ 1 + ( t/\gamma)^{-\phi} \right]^\lambda \left[ 1 + (t/\gamma)^{\phi} \right]} \]
\begin{figure}[htbp!]
\centering
\begin{tikzpicture}
\begin{axis}[
legend pos=north east,
title = {},
xlabel = {time},
ylabel = {temperature},
xmin = 0, xmax = 15,
ymin = 0, ymax = 8,
xtick = {0, 5, 10, 15},
ytick = {0, 2, 4, 6, 8},
]
\addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
\addlegendentry{fitted function}
\addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
\addlegendentry{fitted function2}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
您可以使用键声明函数declare function
。(Ti钾Z 库math
有其他定义函数的方法,但这与 不太协调,pgfplots
因为pgfplots
使用fpu
。)这是一个例子。这将使用声明的函数重现您的图。
\documentclass[letterpaper]{article}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.16}
\begin{document}
\[ y^{\prime} ( t ) = \frac{\lambda \phi ( \beta - \alpha )}{t \left[ 1 + ( t/\gamma)^{-\phi} \right]^\lambda \left[ 1 + (t/\gamma)^{\phi} \right]} \]
\begin{figure}[htbp!]
\centering
\begin{tikzpicture}[declare function={f(\x,\alpha,\beta,\gamma,\lambda,\phi)=%
(\lambda*\phi*( \beta - \alpha ))/(\x*pow( 1 + pow( \x/\gamma,-\phi),\lambda)
*( 1 + pow(\x/\gamma,\phi)));}]
\begin{axis}[
legend pos=north east,
title = {},
xlabel = {time},
ylabel = {temperature},
xmin = 0, xmax = 15,
ymin = 0, ymax = 8,
xtick = {0, 5, 10, 15},
ytick = {0, 2, 4, 6, 8},
]
\addplot[black, no marks, domain=0.01:15, smooth]
{f(x,23.3,42.2,3.15,1.86,3.38)};
%\addplot[black, no marks, domain=0.01:15, smooth]{(1.86*3.38*(42.2 - 23.3))/(x*(1 + (x/3.15)^(-3.38))^(1.86)*(1 + (x/3.15)^(3.38)))};
\addlegendentry{fitted function}
\addplot[red, no marks, domain=0.01:15, smooth]
{f(x,23.8,43.6,1.38,12,3.01)};
%\addplot[red, no marks, domain=0.01:15, smooth]{(12*3.01*(43.6 - 23.8))/(x*(1 + (x/1.38)^(-3.01))^(12)*(1 + (x/1.38)^(3.01)))};
\addlegendentry{fitted function2}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}