Let’s explore a discrete mathematics problem: the Fibonacci sequence, a classic example in combinatorics and discrete mathematics.
Problem: Fibonacci Sequence
The Fibonacci sequence is a series of numbers in which each number (after the first two) is the sum of the two preceding ones.
The sequence starts with 0 and 1, and is defined as follows:
$$
F(0) = 0, \quad F(1) = 1
$$
$$
F(n) = F(n-1) + F(n-2) \quad \text{for } n \geq 2
$$
The sequence goes: $0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …$
The Fibonacci sequence appears in many areas, including biology (e.g., patterns of leaves on a stem) and computer science (e.g., algorithms and data structures).
In this example, we’ll calculate the first $20$ terms of the Fibonacci sequence and visualize the results with a bar graph to illustrate the growth pattern.
Objective
Generate the first $20$ terms of the Fibonacci sequence, then plot the results to observe how the values grow as the sequence progresses.
Python Code
Here’s the Python code to calculate the Fibonacci sequence and visualize it:
1 | import matplotlib.pyplot as plt |
Explanation of the Code
- Fibonacci Sequence Generation:
- We define a function
fibonacci_sequencethat generates the firstnterms of the Fibonacci sequence using a loop. - Starting with
[0, 1], we append each new term as the sum of the two previous terms.
- We define a function
- Plotting the Sequence:
- We use a bar graph to visualize the terms in the Fibonacci sequence.
- The $x$-$axis$ represents the term index $(n)$, and the $y$-$axis$ represents the value of the Fibonacci number at that index.
Visualization
The resulting bar graph displays the first $20$ terms of the Fibonacci sequence:
- The values grow slowly at first but increase rapidly as the index gets higher, showing the characteristic exponential growth pattern of the Fibonacci sequence.
- This growth pattern illustrates how the Fibonacci sequence can approximate exponential growth, even though each term is the sum of only two preceding terms.

Applications
The Fibonacci sequence has various applications:
- Computer Science: Recursive algorithms, dynamic programming.
- Biology: Natural patterns, such as branching in trees and arrangement of leaves.
- Finance: Technical analysis in stock trading.
This example demonstrates how $Python$ can be used to solve discrete math problems and visualize sequences that exhibit interesting growth patterns.







