0
$\begingroup$

Of course, I know I can use Plot and DiscretePlot plot the built-in Fibonacci[x], but why this code don't work?

We can find the formula in wiki here:

Plot[1/Sqrt[5] (((1 + Sqrt[5])/2)^x - ((1 - Sqrt[5])/2)^x), {x, 0, 26}]

enter image description here

Is it a bug of MMA?

$\endgroup$
0
4
$\begingroup$

Your expression is only valid for integer x

FunctionDomain[
  1/Sqrt[5] (((1 + Sqrt[5])/2)^x - ((1 - Sqrt[5])/2)^x), x]

(* Element[x, Integers] *)

The correct expression for arbitrary real x is

f[x_] = Fibonacci[x] // FunctionExpand

(* ((1/2 (1 + Sqrt[5]))^x - (2/(1 + Sqrt[5]))^x Cos[π x])/Sqrt[5] *)

% // FullSimplify

(* (2^-x ((1 + Sqrt[5])^x - (-1 + Sqrt[5])^x Cos[π x]))/Sqrt[5] *)

Plot[f[x], {x, -5, 5}]

enter image description here

$\endgroup$
1
  • $\begingroup$ I know we can plot Fibonacci[x], I just don't know why I cannot plot my that formula.. :) $\endgroup$
    – yode
    Dec 2 '21 at 7:37
3
$\begingroup$

It is not the right function for the Fibonacci numbers. Especially, you use the term

 ((1 - Sqrt[5])/2)^x)

but $ (1 - Sqrt[5])/2)<0 $

The power function with negative base is not real for general real $ x $

The correct way is

Plot[1/Sqrt[5]* (((1 + Sqrt[5])/2)^x - ((-1 + Sqrt[5])/2)^x), {x, 1, 26}]

with the result

enter image description here

$\endgroup$
3
  • $\begingroup$ Look wiki here $\endgroup$
    – yode
    Dec 2 '21 at 7:30
  • $\begingroup$ Why the base cannot be less than 0? $\endgroup$
    – yode
    Dec 2 '21 at 7:36
  • $\begingroup$ OK, I am correcting: Your function is defined for integer x only, but in that case, it does not support the Plot function. The better version is ListPlot[(1/Sqrt[5] (((1 + Sqrt[5])/2)^# - ((1 - Sqrt[5])/2)^#)) & /@ Range[0, 26]] $\endgroup$ Dec 2 '21 at 9:23
1
$\begingroup$

You have these two expressions in your plot.

t = List @@ (1/Sqrt[5] ((1 + Sqrt[5])/2)^x - 
    1/Sqrt[5] ((1 - Sqrt[5])/2)^x)

$$\left\{-\frac{\left(\frac{1}{2} \left(1-\sqrt{5}\right)\right)^x}{\sqrt{5}},\frac{\left(\frac{1}{2} \left(\sqrt{5}+1\right)\right)^x}{\sqrt{5}}\right\}$$

The second one can be plotted for x < 0; but consider:

t[[1]] /. x -> 0.4 // N

-0.113999 - 0.350854 I

So you cannot Plot this complex number.

$\endgroup$
1
  • $\begingroup$ Thanks very very much $\endgroup$
    – yode
    Dec 2 '21 at 7:57
0
$\begingroup$

I can Plot it by add a Re now

Plot[Re[1/Sqrt[5] (((1 + Sqrt[5])/2)^x - ((1 - Sqrt[5])/2)^x)], {x, 1, 25}]

enter image description here

$\endgroup$
1
  • 3
    $\begingroup$ So, why Re and not Abs, Re+Im? Looks like an arbitrary question (because it is not specified in what sense the interpolation should be given). Also, looks like an arbitrary answer (because not explained why certain choice is made). $\endgroup$
    – yarchik
    Dec 2 '21 at 9:16

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