1
$\begingroup$

I would like to go for search for this given functional equation using either java or python $$ f(x+1) = f(x)^2-1 $$ $$ f(0) = 1 $$ I don't know where to start. I know how to graph in pycharm. I know basics in animation like object collision in java. I don't know how to go for estimation search for functional equations or in other manners any search whatsoever. If some one can give me both the algorithm and the manner for which I can program it, I would be glad.

$\endgroup$
  • $\begingroup$ When you say you wish to "search for" the functional equation, are you trying to search the internet for information about it, or are you trying to solve it numerically (or something else entirely)? $\endgroup$ – Theo Bendit May 11 at 13:15
  • $\begingroup$ Actually, $f^2(x)=f(f(x))$ and $f(x)^2=(f(x))^2.$ $\endgroup$ – Michael Rozenberg May 11 at 13:18
  • $\begingroup$ No solving it numerically. $\endgroup$ – Alireza Rouhani May 11 at 13:18
  • $\begingroup$ Mostly just graphing it. $\endgroup$ – Alireza Rouhani May 11 at 13:19
  • $\begingroup$ @MichaelRozenberg Just fix it. Thank you. $\endgroup$ – Alireza Rouhani May 11 at 13:26
1
$\begingroup$

Let's look at some of its algebraic properties on the integers $\mathbb Z$.

For negative initial values, this immediately squares to become positive and for absolute values of $2$ or above, this will naturally grow exceedingly fast.

For moderate values, the square will instead push it down. If $f(x)=0$, then $f(x+1)=0^2-1=-1$ and if $f(x)=\pm 1$, then $f(x+1)=(\pm 1)^2-1=0$. In other words, once you touch the ground, you'll forever bounce down and back again.

So this is akin to $-r(x,x_0,y_0)\cdot\frac{1}{2}\cdot(1-(-1)^x)$ for some $r$ shirking with $x$.

On the reals, you may find some variation of functions with trigonometric relations (alla those of $\sin(\pi x)-1$).

I wrote you your python script and for the values I display here all values eventually end up in that pendulum.

enter image description here

import matplotlib.pyplot as plt

x0 = -5
xfin = 10
xs = range(x0, xfin)

num_ys = 30
y_max = 1.5
y0s = [y_max * y / num_ys for y in range(-num_ys, num_ys)]

for y0 in y0s:

    def f(x):
        return y0 if x==x0 else f(x - 1)**2 - 1

    ys = map(f, xs)

    plt.plot(xs, ys)

plt.show()

If efficiency should be a concern, note that here in this implementation of constructing the ys, I do some unnecessary re-computation.

$\endgroup$
  • $\begingroup$ Thank you. Is there way to make these graphs smooth?. $\endgroup$ – Alireza Rouhani May 11 at 14:05
  • $\begingroup$ @AlirezaRouhani Should be doable, but to avoid accidental infinite recursion on $f(x - 1)$, you should use a rational number library or the check $x=x_0$ should be replaced with your own implementation of an approximate equality. Keep in mind that there's few programming languages where $0.1 + 0.2$ is $0.3$, see https://0.30000000000000004.com/. $\endgroup$ – Nikolaj-K May 11 at 14:13
  • $\begingroup$ Thank you. That was very kind. $\endgroup$ – Alireza Rouhani May 11 at 14:16
  • $\begingroup$ @AlirezaRouhani, if you find an answer helpful, please mark it as such. $\endgroup$ – NoChance May 11 at 14:29
  • $\begingroup$ @Nikolaj-K, I ran the program, It is giving me error on plt.plot. I don't know why. $\endgroup$ – Alireza Rouhani May 11 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.