如何使用 pgfplots 绘制以下函数 $w(s)$ 的图形?

如何使用 pgfplots 绘制以下函数 $w(s)$ 的图形?

如何使用 pgfplots 绘制以下函数 $w(s)$ 的图形? 在此处输入图片描述


从评论复制:

% !TEX program = LuaLaTeX % !Mode:: "TeX:UTF-8"

\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfmathdeclarefunction{vs}{1}{%
 \pgfmathparse{(2-#1)/(2*#1)*((pi-x)/pi)^3-((pi-x)/pi)/#1+0.5}% 
} 
 
\begin{document} 

I can only plot the graph of function $v(s)$, for the case of the composite of the two, I do not know how to deal with it.

\begin{tikzpicture}
    \begin{axis}[domain=0:2*pi, samples=100] 
    \addplot [very thick,black] {vs(4)}; 
    \end{axis} 
\end{tikzpicture}
\end{document}
% !Mode:: "TeX:UTF-8"
% !TEX program = Lualatex
\documentclass[12pt]{article}
\usepackage{luacode}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%%----------------------------
\begin{luacode*}
local pei=math.pi

local fvs = function(q,s)
temp1=(pei-s)/pei
temp2=(2.0-q)/(2.0*q)*(temp1)^3-temp1/q+0.5
return temp2
end

local fws = function(q,s)
temp1=fvs(q,s)^q
temp2=2.0*pei*temp1/(temp1+fvs(q,2.0*pei-s)^q)
return temp2
end

thirddata = thirddata or {}
thirddata.fws = function(q,s)
return tex.print(fws(q,s))
end
\end{luacode*}
%%----------------------------
\begin{document}
\begin{equation}
w(s)=2\pi\frac{[v(s)]^q}{[v(s)]^q+[v(2\pi-s)]^q},\quad 0\leq
s\leq 2\pi,
\end{equation}
\begin{equation}
v(s)=\left(\frac{1}{q}-\frac{1}{2}\right)\left(\frac{\pi-s}{\pi}\right)^3+\frac{1}{q}\frac{s-\pi}{\pi}+\frac{1}{2}.
\end{equation}
and $q\geq 2$

\begin{figure}[!htpb]
\centering

\begin{tikzpicture}
[declare function={
fws(\q,\x) = \directlua{thirddata.fws(\q,\x)};
}]

\begin{axis}[
use fpu=false,
domain=0:2*pi, xlabel=$s$, ylabel=$w(s)$, samples=100, legend pos=north west
]

\addplot[red,thick,domain=0:2*pi,samples=200] {fws(3,x)};
\addlegendentry{ $ q=3$}
\addplot[green,thick,domain=0:2*pi,samples=200] {fws(5,x)};
\addlegendentry{ $ q=5$}
\addplot[blue,thick,domain=0:2*pi,samples=200] {fws(8,x)};
\addlegendentry{ $ q=8$}
\end{axis}

\end{tikzpicture}
\caption{$w(s)$ for $q=3,q=5,q=8$ }
\end{figure}

\end{document} 

答案1

我认为解决方案如下 [編輯]

\documentclass[12pt]{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
 
\begin{document} 
I can only plot the graph of function $v(s)$, for the case of the composite of the two, I do not know how to deal with it.

% the w(s) function 
\pgfmathdeclarefunction{ws}{1}{%
 \pgfmathparse{2*pi*(((vs(#1))^#1)/(((vs(#1))^#1)+((vpis(#1))^#1)))}% 
}

% the v(s) function
\pgfmathdeclarefunction{vs}{1}{%
 \pgfmathparse{(2-#1)/(2*#1)*((pi-x)/pi)^3-((pi-x)/pi)/#1+0.5}% 
}

% the v(2pi-s) function
\pgfmathdeclarefunction{vpis}{1}{%
 \pgfmathparse{(2-#1)/(2*#1)*((pi-(2*pi-x))/pi)^3-((pi-(2*pi-x))/pi)/#1+0.5}% 
}

\begin{tikzpicture}
    \begin{axis}[domain=0:2*pi, xlabel=$s$, ylabel=$w(s)$, samples=100, legend pos=north west]
    \addplot [very thick,blue] {ws(2)};\addlegendentry{$p=2$} % w(s) plot with p=2
    \addplot [very thick,green] {ws(10)};\addlegendentry{$p=10$} % w(s) plot with p=10
    \addplot [very thick,yellow] {ws(80)};\addlegendentry{$p=80$} % w(s) plot with p=80
    \end{axis} 
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容