[Mathematica] Simple Problem with the plot function

Click For Summary

Discussion Overview

The discussion revolves around a problem encountered while using Mathematica to plot the Fibonacci sequence and its relationship to the square function. Participants explore the issues related to plotting functions that involve complex numbers and the implications for real-valued outputs.

Discussion Character

  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant shares a formula for the Fibonacci sequence and notes an issue with plotting it alongside the function y = n^2, specifically that only the x^2 graph appears.
  • Another participant explains that the problem arises because the plot function attempts to create a continuous plot, which fails for non-integer values of the term involving phih, as it is not real-valued.
  • There is a suggestion to use DiscretePlot to visualize the function at integer values of n, which is noted as a useful approach.
  • One participant reflects on the nature of the term (1 - Sqrt[5])/2 being negative and how raising it to non-integer powers results in imaginary numbers, questioning its implications for real-valued functions.
  • A later reply elaborates on the conditions under which a function is considered real-valued, discussing the behavior of negative bases raised to non-integer powers and the use of complex logarithms.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the problem related to real-valued functions and the use of DiscretePlot, but there is no consensus on the best approach to handle complex values in plotting.

Contextual Notes

The discussion highlights the limitations of Mathematica's plotting capabilities when dealing with complex numbers and the need for careful consideration of the function's domain.

PEZenfuego
Messages
48
Reaction score
0
I have a formula for the fibonacci sequence (with 1 being the first) and I noticed that the 12th fibonacci number was 144. I thought that was a neat coincidence, so I I headed over to mathematica to see if this (and 1) were the only numbers that had this property. I was almost certain that it was. So I plotted the two graphs, but only the x^2 graphed showed up. Here was my input. My question is about what I did wrong.

phi := (1 + Sqrt[5])/2

phih := (1 - Sqrt[5])/2

f:={(phi^n)-(phih^n)}/{Sqrt[5]}

y:=n^2

Plot[{f, y}, {n, -20, 20}]

Now, this works when I remove the phih term, which works well enough that I can clearly see that only 1 and 12 are solutions. On the other hand, this is not plotting something that it should be plotting...

Anyway, thank you in advance for the help.
 
Physics news on Phys.org
The problem is that plot tries to make a continuous plot. It then runs into the problem that phih^x is not a real-valued function for non-integer x, and refuses to plot it altogether. To just plot the values at integer values of x, you can use DiscretePlot:

DiscretePlot[{f, y}, {n, -20, 20, 1}]
 
Hypersphere said:
The problem is that plot tries to make a continuous plot. It then runs into the problem that phih^x is not a real-valued function for non-integer x, and refuses to plot it altogether. To just plot the values at integer values of x, you can use DiscretePlot:

DiscretePlot[{f, y}, {n, -20, 20, 1}]

That's really neat and useful. I was so accustomed to just glazing over (1-Sqrt[5])/2, that I forgot that it was negative. If you raise it to the power of 1/2 for example, then the answer is imaginary. That's why it is not a real-valued function, correct? Thank you, sir.
 
PEZenfuego said:
That's really neat and useful. I was so accustomed to just glazing over (1-Sqrt[5])/2, that I forgot that it was negative. If you raise it to the power of 1/2 for example, then the answer is imaginary. That's why it is not a real-valued function, correct? Thank you, sir.

You are welcome. And, yeah, if the function has a non-zero imaginary part for at least one value of x, then clearly it's not real-valued on the whole domain (i.e. the plot range). However, Mathematica is able to handle cases where the function is piecewise real-valued, it just doesn't plot the part where the values are comples, see eg.
Plot[(1 + I*HeavisideTheta[x - 5]*HeavisideTheta[6 - x]), {x, 0, 10}]
(I would prefer it to give an error message or a warning, but it doesn't seem to do that.)Your function is a bit worse though as it is only real-valued on integer values of x. The proof just uses the general definition of the power of a number a (negative, complex etc.), which makes use of the complex logarithm:
a^b=e^{b log a}.
If a is real and negative, then this simplifies to
a^b=e^{bLog(|a|)+ib\pi}=|a|^b e^{ib\pi},
which is only real for integer values of b.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K