我想画以下
我的方法是从 sin^2 开始,然后用 rand 改变频率。到目前为止,我的解决方案如下
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{siunitx}
\usepackage{nicefrac}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture} [
declare function={fy(\x)=sin(\x+rand*100)^2;}
]
\begin{axis} [
xmin=-720, xmax=720,
width=10cm, height=10cm,
tick style=black,
clip mode=individual,
x axis line style={opacity=0},
y axis line style={opacity=0},
ticks=none
]
\addplot [
ultra thick,
smooth,
tension=1,
samples=30,
domain=-720:720
] {fy(x)};
\draw[latex-latex, xshift=-0.5cm] ({rel axis cs:0,0}|-{rel axis cs:0,0}) -- ({rel axis cs:0,0}|-{rel axis cs:0,1}) node[left, pos=0.5] {$h$};
\end{axis}
\end{tikzpicture}
\end{document}
调整参数:张力、随机因子、样本,我已经接近期望的输出,但如果有人有其他想法……除此之外,有没有办法缩放 ymax 和 ymin 以使其适合随机结果?我不知道为什么,但有时我得到的正弦值大于 1 且小于 0。我真的不明白为什么。当前输出是
答案1
这看起来像调频,因此函数的频率应该在域内变化。下面是每次选择不同值但在整个图中保持不变的示例。
代码
\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\pgfmathsetmacro{\amplitudefluctuationfrequency}{2+rnd}
\pgfmathsetmacro{\amplitudefluctuationamplitude}{0.1+rand*0.4}
\pgfmathsetmacro{\frequencyfluctuation}{0.5+rand*0.05}
\begin{tikzpicture} [
declare function={fy(\x)=(1+sin(\x*\amplitudefluctuationfrequency)*\amplitudefluctuationamplitude)*sin(\x*1.47*(cos(\x*\frequencyfluctuation)*0.5+1.5));}
]
\begin{axis} [
xmin=-720, xmax=720,
width=10cm, height=10cm,
tick style=black,
clip mode=individual,
x axis line style={opacity=0},
y axis line style={opacity=0},
ticks=none
]
\addplot [
ultra thick,
smooth,
tension=1,
samples=1440,
domain=-720:720
] {fy(x)};
\draw[latex-latex, xshift=-0.5cm] ({rel axis cs:0,0}|-{rel axis cs:0,0}) -- ({rel axis cs:0,0}|-{rel axis cs:0,1}) node[left, pos=0.5] {$h$};
\end{axis}
\end{tikzpicture}
\end{document}