<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pratik Das on Medium]]></title>
        <description><![CDATA[Stories by Pratik Das on Medium]]></description>
        <link>https://medium.com/@mr-pratik-das?source=rss-3384cbd756d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gDZrKLGTF0K8QXC8QW7SVA.jpeg</url>
            <title>Stories by Pratik Das on Medium</title>
            <link>https://medium.com/@mr-pratik-das?source=rss-3384cbd756d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 07:29:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mr-pratik-das/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Complex Evolution of Binet Formula]]></title>
            <link>https://mr-pratik-das.medium.com/complex-evolution-of-binet-formula-8ee7a319c957?source=rss-3384cbd756d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ee7a319c957</guid>
            <category><![CDATA[fibonacci-sequence]]></category>
            <category><![CDATA[binet-formula]]></category>
            <category><![CDATA[complex-plot]]></category>
            <dc:creator><![CDATA[Pratik Das]]></dc:creator>
            <pubDate>Sat, 03 Feb 2024 15:20:44 GMT</pubDate>
            <atom:updated>2024-02-03T15:20:44.225Z</atom:updated>
            <content:encoded><![CDATA[<p>Fibonacci Sequence is one of the most famous and well-studied sequences in the field of mathematics. The numbers in the sequence (known as <strong>Fibonacci Numbers</strong>) appear in a lot of natural settings (one personal favourite being, sunflower seed spirals). The sequence even appears in the famous <a href="https://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot Set</a>. Of course, one can go further deep into the praises of the Fibonacci sequence, but that is not gonna be the topic of this article.</p><p>In this article, I want to explore what happens when we subtitute a complex number (ℂ) for <em>n</em> in the Binet formula, instead of the more familiar natural numbers (ℕ). But, I’m getting ahead of myself and taking a big leap. So, let&#39;s take it a little easy!</p><p>Now as provided in <a href="https://en.wikipedia.org/wiki/Fibonacci_sequence#Closed-form_expression">this wikipedia article</a>, the Fibonacci Sequence can be generated using the following expression known as the <strong>Binet’s formula</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*x9DgLqi5JwIVSeeZOvMgKA.png" /></figure><p><a href="https://twitter.com/standupmaths?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor">Matt Parker</a> made an exceptional video about the complex values of the formula on <a href="https://youtu.be/ghxQA3vvhsk?si=qe9WZCv08jvfbLh1">his YouTube channel</a>, in which he extended the domain of <em>n</em> from natural numbers (ℕ) to real numbers (ℝ) and presented the following plot on a complex plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*XOnwLTDwQMqveuHJ6I__cA.png" /></figure><pre>import matplotlib.pyplot as plt<br>import numpy as np<br><br><br>def plot_binet2d(x_start, x_end, step) -&gt; None:<br>    PHI = (1 + np.sqrt(5)) / 2 + 0j # 0j is added in order to type cast PHI from float to complex<br>    PSI = 1 - PHI<br><br>    x = np.arange(x_start, x_end, step)<br>    x = np.meshgrid(x)<br><br>    f: complex = (PHI**x - PSI**x) / np.sqrt(5)<br><br>    fig, ax = plt.subplots()<br>    ax.plot(f.real[0], f.imag[0])<br>    ax.set(xlabel=&quot;$f_{real}$&quot;, ylabel=&quot;$f_{imag}$&quot;)<br>    ax.grid()<br><br>    plt.show()<br><br><br>if __name__ == &quot;__main__&quot;:<br>    plot_binet2d(0, 5, 0.01)</pre><p>As mentioned previously, I wanted to extend the domain of <em>n</em> further, from real numbers (ℝ) to complex numbers (ℂ). Of course, the obvious thing to notice is that the graph would be complex, again. But, how exactly would it evolve as one introduces an imaginary part into <em>n</em>? In other words, I wanted to know how would the plot change, which Matt introduced in his video, with a changing value of <em>imag(n)</em>. To achieve this, I represented <em>n</em> as <em>x + iy, </em>a complex number<em> </em>(with <em>i = √-1</em>), within the domain <em>x ∈ [0, 5]</em> and <em>y ∈ [-0.5, 0]</em>. The result is the following 3D plot, generated in Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*mEUxi74Zt6pOnqJkMge_CQ.png" /></figure><pre>import matplotlib.pyplot as plt<br>import numpy as np<br>from matplotlib import cm<br><br><br>def plot_binet3d(<br>    x_start: float, x_end: float, y_start: float, y_end: float, step: float<br>) -&gt; None:<br>    PHI: float = (1 + np.sqrt(5)) / 2 + 0j<br>    PSI: float = 1 - PHI<br><br>    x = np.arange(x_start, x_end, step)<br>    y = np.arange(y_start, y_end, step)<br>    x, y = np.meshgrid(x, y)<br><br>    f = ((PHI**x) * (PHI ** (y * 1j)) - (PSI**x) * (PSI ** (y * 1j))) / (PHI - PSI)<br>    f_r = f.real<br>    f_i = f.imag<br><br>    fig, ax = plt.subplots(subplot_kw={&quot;projection&quot;: &quot;3d&quot;})<br>    surf = ax.plot_surface(<br>        f_r, y, f_i, cmap=cm.viridis_r, linewidth=0, antialiased=True<br>    )<br>    ax.set(xlabel=&quot;$f_{real}$&quot;, ylabel=&quot;y&quot;, zlabel=&quot;$f_{imag}$&quot;)<br>    ax.grid()<br>    plt.show()<br><br><br>if __name__ == &quot;__main__&quot;:<br>    plot_binet3d(0, 5, -0.5, 0, 0.001)</pre><p>The <em>x</em>-axis of the image represents <em>real(F)</em>, the <em>z</em>-axis represents <em>imag(F)</em> and the <em>y</em>-axis represents <em>y</em> (<em>=imag(n)</em>). A more clearer plot is as follows, generated in MATLAB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*RIWoWHo5j2NGhdfSl51zgw.png" /></figure><pre>plot_binet3(0, 5, -.5, 0, 0.01)<br><br>function plot_binet3(x_start, x_end, y_start, y_end, step)<br>    PHI = (1 + sqrt(5)) / 2;<br>    PSI = 1 - PHI;<br><br>    x = x_start : step : x_end;<br>    y = y_start : step : y_end;<br>    [x, y] = meshgrid(x, y);<br>    z = complex(x, y);<br><br>    f = (PHI .^ z - (PSI) .^z) / (PHI - PSI);<br>    f_r = real(f);<br>    f_i = imag(f);<br><br>    surf(f_r, y, f_i, &#39;FaceAlpha&#39;, 0.5);<br>    xlabel(&#39;f_{real}&#39;);<br>    ylabel(&#39;y&#39;);<br>    zlabel(&#39;f_{imag}&#39;);<br>    shading interp;<br>    grid on;<br>    rotate3d on;<br>end</pre><p>In both the plots above, on the <em>xz</em>-plane at <em>y = 0, </em>you can catch a glimpse of the 2D curve (that Matt presented us). This becomes more evident when we rotate the 3D plot to a different angle and zoom in a bit closer, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*BuHFt87uEaQTXwTA9TGrDA.png" /></figure><p>And now we know why there was a kink in the original 2D plot. The<br>loop-the-loop which <a href="https://youtu.be/ghxQA3vvhsk?si=Zo1zHghpan8VaVoU&amp;t=383">excited</a> Matt was formed because the plot curls over itself and not only once but multiple times. This is more clearly evident in the plots by <a href="https://math.stackexchange.com/users/530932/lawton">Lawton</a>, shared on <a href="https://math.stackexchange.com/q/4474029/804307">his stackexchange post</a>. For <em>y = 0</em>, he extended the value of <em>n</em> from -∞ to +∞ and spread out the curve along a 3rd axis to make the picture more clearer. Not only that but these loops grow as one decreases the value of <em>y</em> towards -∞, and they iron out if we increase the value of <em>y</em> towards +∞.</p><p>The same can be seen in the following animation when the value of <em>y</em> changes from -5 to +5<em>.</em> We start with a bigger loop, but as <em>y</em> progresses towards +∞, the loops keep on shrinking until finally straightening out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZqpZaWSA4oUkeB0_SmP0w.gif" /></figure><pre>import matplotlib.pyplot as plt<br>import numpy as np<br>from matplotlib.animation import FuncAnimation, PillowWriter<br><br>PHI = (1 + np.sqrt(5)) / 2 + 0j<br>PSI = 1 - PHI<br><br>PLOT = &quot;centre&quot;<br><br><br>class Update:<br>    def __init__(self, ax, x_start, x_end, step, offset=0) -&gt; None:<br>        self.ax = ax<br>        self.x_start = x_start<br>        self.x_end = x_end<br>        self.step = step<br>        self.offset = offset<br>        self.x = np.arange(x_start, x_end, step)<br>        self.f = lambda x, y: (<br>            PHI**x * PHI ** (y * 1j) - PSI**x * PSI ** (y * 1j)<br>        ) / (PHI - PSI)<br>        self.fri(0 + self.offset)<br>        (self.line,) = ax.plot(self.fr, self.fi, &quot;k-&quot;)<br>        self.ax.set(xlabel=&quot;$f_{real}$&quot;, ylabel=&quot;$f_{imag}$&quot;)<br>        self.ax.grid(True)<br><br>    def fri(self, y) -&gt; None:<br>        self.fr = self.f(self.x, y).real<br>        self.fi = self.f(self.x, y).imag<br><br>    def start(self):<br>        return (self.line,)<br><br>    def __call__(self, y):<br>        y += self.offset<br>        y *= self.step<br>        self.fri(y)<br>        if PLOT == &quot;fix&quot;:<br>            self.ax.set_xlim(min(self.fr), max(self.fr))<br>            self.ax.set_ylim(min(self.fi), max(self.fi))<br>        if PLOT == &quot;centre&quot;:<br>            self.ax.set_xlim(-5, 5)<br>            self.ax.set_ylim(-2, 2)<br>        self.line.set_data(self.fr, self.fi)<br>        return (self.line,)<br><br><br>def animate_binet(x_start, x_end, step, offset=0):<br>    fig, ax = plt.subplots()<br>    ud = Update(ax, x_start, x_end, step, offset)<br>    anim = FuncAnimation(<br>        fig,<br>        ud,<br>        init_func=ud.start,<br>        frames=100,<br>        interval=100,<br>        blit=True,<br>    )<br>    plt.show()<br><br><br>if __name__ == &quot;__main__&quot;:<br>    animate_binet(0, 5, 0.01, -60)</pre><h3><strong>So, why the loops? Also, why no loops?</strong></h3><p>To answer this, let’s revisit the Binet Formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*x9DgLqi5JwIVSeeZOvMgKA.png" /></figure><p>Well the simple answer is that these loops are the result of extending the sequences backwards (meaning, <em>n &lt; 0</em>). We recover the same Fibonacci numbers but with alternating signs. This is because the term ϕⁿ — ψⁿ in the numerator controls the behaviour of the curve (the denominator is just a constant, <em>√5</em>). As 𝜙 &gt; 1, for values of <em>n &gt; 0, </em>ϕⁿ dominates which is always greater than 0 and we do not get any further loops for <em>n &gt; 0.</em> But since |𝜓| &lt; 1, for values of <em>n &lt; 0, </em>ψⁿ<em> </em>dominates and we can see the loops because 𝜓 &lt; 0. ψⁿ keeps on swinging from positive value (when, <em>n</em> is <em>even</em>) to negative value (when <em>n</em> is <em>odd</em>) which results in the loops of the curve.</p><p>The swirling and curling of the curve was always there, but introducing an imaginary part into <em>n</em> just made the effect more vivid!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ee7a319c957" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>