pages tagged related/math-related canvon's blog https://blog.canvon.de/tags/related/math-related/ canvon's blog ikiwiki 2020-07-27T23:03:54Z gnuplot: Cosine oscillating on arbitrary function https://blog.canvon.de/posts/cosine_oscillating_on_function/ Fabian &#x22;canvon&#x22; Pietsch Copyright © 2020 <a href="../../../canvon/">Fabian "canvon" Pietsch</a> 2020-07-27T23:03:54Z 2020-04-09T00:40:08Z <h1><span id="gnuplot-cosine-oscillating-on-arbitrary-function"><code>gnuplot</code>: Cosine oscillating on arbitrary function</span></h1> <p>To let a cosine oscillate on an "arbitrary" function, when the function goes up the <em>x</em> coordinate might go backwards, so we can't express this as a single-valued function from <em>x</em> to <em>y</em>. But we can use parametric curves, instead; they go from a separate parameter, <em>t</em>, to points (<em>x</em>(<em>t</em>), <em>y</em>(<em>t</em>)). (In <code>gnuplot</code>, this is <code>set parametric</code>.)</p> <div class="scale-down"><p>As starter, here is what the final result will look like for cosine oscillating on cosine:<br /> <img src="https://blog.canvon.de/posts/cosine_oscillating_on_function/cosine_on_cosine.png" alt="gnuplot result of cosine on cosine" /><br /> This is what motivated myself to write up a blog post about the topic.</p></div> <p><code>gnuplot</code> source code of <code>cosine_on_cosine</code>:</p> <div class="highlight-txt"><pre class="hl"> #!/usr/bin/gnuplot -persist set parametric f(x) = cos(x*2.*pi) fDeriv(x) = -sin(x*2.*pi) g(x) = 0.1*cos(8.*x*2.*pi) periods=3 set title GPFUN_g.' on '.GPFUN_f set samples periods*100 plot [0:periods][-0.5:3.5][-2:2] \ t, f(t) with points, \ t + cos(atan(fDeriv(t)) + pi/2.)*g(t), f(t) + sin(atan(fDeriv(t)) + pi/2.)*g(t) with points set samples 100 </pre></div> <p><a href="https://blog.canvon.de/posts/cosine_oscillating_on_function/cosine_on_cosine.gnuplot.txt">View raw file</a></p> <p><em>...</em></p> <p>[2020-07-27] Sadly, I never got around to write up the full blog post, and now have already forgotten all the details. Let's get this published anyway, now, so I can get on with other things, here...</p> <p>(Created <em>Thu 09 Apr 2020 02:40:08 CEST</em>, published around <em>Mon 27 Jul 2020 22:40:00 CEST</em>.)</p>