我想要绘制函数 X^(-1.5)*cos(ln(X)),我可以成功完成 X^(1.5)*cos(ln(X)),但如果我输入负指数,代码就不起作用。
我想绘制一个函数,该函数在靠近墙壁时会增加,并且振荡波长也会增加。有人能帮忙吗?谢谢!
\draw[-stealth] (0,-2) -- (0,2);
\draw[-stealth] (0,0) -- (5,0);
\draw [scale=0.5,domain=10:0,smooth,variable=\x,blue] plot (\x, { 0.1*cos(1200* ln(\x))*(\x)^(1.5) });
\draw [scale=0.5,domain=10:0,smooth,variable=\x,black] plot (\x, { 0.1*\x^(1.5) });
\draw [scale=0.5,domain=10:0,smooth,variable=\x,black] plot (\x, { -0.1*\x^(1.5) });
答案1
您可以按照我上面的建议,使用 cos(ln(x))/x^(1.5) 修改 @marmot 代码。为了让图表看起来更美观,我使用了一个模板:
\documentclass{standalone}
\usepackage[dvipsnames]{xcolor}%declare color here to avoid color clash with tikz
\usepackage{pgfplots}% This uses tikz
\pgfplotsset{compat=newest}% use newest version
\pgfmathdeclarefunction{f}{1}{%
\pgfmathparse{.1/x^(1.5)}%
}
\pgfplotsset{compat=newest}% use newest version
\pgfmathdeclarefunction{g}{1}{%
\pgfmathparse{0.1*cos(1200*ln(x))/x^1.5}%
}
\pgfplotsset{compat=newest}% use newest version
\pgfmathdeclarefunction{h}{1}{%
\pgfmathparse{-.1/x^(1.5)}%
}
\tikzset{Line Style1/.style={smooth,thick, dashed,samples=400}}
\tikzset{Line Style2/.style={smooth,thick, samples=800}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
%grid = both,%grid for major ticks (every integer) and minor ticks
minor tick num=4,% number of hor/vert lines in a box
every major grid/.style={Red!30, opacity=1.0},%set the color for major grid
every minor grid/.style={ForestGreen!30, opacity=1.0},%set the color for minor grid
height= 1\textwidth,%compress height: eg height=0.5\textwidth
width = 1\textwidth,%compress width: eg width=0.5\textwidth
thick,
black,%Set the color of the main axes and numbers
scale=1.0,
axis lines=center,
domain=0:4
samples=500,
line join=bevel,
xmin=0,
xmax=2,
ymin=-4,
ymax=4,
%xticklabels=\empty,% remove % at beginning of line to remove x labels
%yticklabels=\empty,% remove % at beginning of line to remove x labels
major tick length=0pt,% Increase number adds tick mark and increases distance of numbers from the x/y axis
minor tick length=0pt,% Increase number adds minor tick marks
%xtick=\empty,
%ytick=\empty,
]
\addplot[Line Style2, color=Peach, domain=.01:2] (\x,{f(\x)}); %color names determined by dvipsnames
\addplot[Line Style2, color=NavyBlue, domain=0.05:2] (\x,{g(\x)});% in the xcolor package
\addplot[Line Style2, color=Peach, domain=0.01:2] (\x,{h(\x)});
\end{axis}
\end{tikzpicture}
\end{document}
当您从右侧接近 y 轴时,您需要调整域的值以使图看起来赏心悦目:越接近 0,图形就越混乱。以至于它看起来像一个纯蓝色区域,而不是曲线。设置为 .05 时,图形看起来还不那么混乱。
答案2
下面是一些生成该图的 pgfplots 代码。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0.01:10,no marks,axis lines=middle,smooth,
xmax=12,xlabel=$\eta$,xtick=\empty,ytick=\empty]
\addplot[color=blue,samples=101] {0.1*cos(1200*ln(x))*pow(x,1.5)}; %
\addplot[color=black] { 0.1*pow(x,1.5) };
\addplot[color=black] {-0.1*pow(x,1.5)};
\end{axis}
\end{tikzpicture}
\end{document}
也可以用 Ti 绘制钾Z,我认为@DJP 会给你提供一个代码。
如果你想让物体向墙壁变大,你可以使用
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0.01:10,no marks,axis lines=middle,smooth,
xmax=12,xlabel=$\eta$,xtick=\empty,ytick=\empty,ymin=-4.5,ymax=4.5]
\addplot[color=blue,samples=101] {0.1*cos(1200*ln(10-x))*pow(10-x,1.5)}; %
\addplot[color=black] { 0.1*pow(10-x,1.5) };
\addplot[color=black] {-0.1*pow(10-x,1.5)};
\end{axis}
\end{tikzpicture}
\end{document}