0% found this document useful (0 votes)
30 views

Fibonacci Sequence Generator 2

Report on Fibonacci

Uploaded by

vpawar2544
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Fibonacci Sequence Generator 2

Report on Fibonacci

Uploaded by

vpawar2544
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

A report on

“Fibonacci Sequence Generator"

Walchand College of Engineering, Sangli


(An Autonomous Institute)

DEPARTMENT OF MECHANICAL ENGINEERING


Polytechnic Wing

submitted by
Sakshi Mali -262
Dhanashri Salunkhe -266
Shreya Gavali - 252

under the guidance of


Prof. S.U. Patil

1
Walchand College of Engineering, Sangli
(An Autonomous Institute)

CERTIFICATE

Certified that this project report titled " Fibonacci Sequence Generator " is the original work of
the undersigned, carried out under my supervision and guidance. The project has been prepared in
partial fulfillment of the requirements for the award of the Second Year Mechanical Diploma at
Walchand College of Engineering, Sangli, for the academic year 2024-2025. This work reflects
the dedication, research, and effort invested by the student in understanding the Fibonacci
Sequence Generator.

Prof. A. V. Kamble Prof. S.U. Patil


Head of Department Guide

2
ACKNOWLEDGEMENT

It gives us a great pleasure to acknowledge the contribution of all those who have directly or
indirectly contributed to the completion of this project.
I express my foremost and deepest gratitude to my guide Prof.S.U.patil for her supervision, noble
guidance and constant encouragement in carrying out the project. I am deeply indebted to Prof.
A.V.Kamble, Head of Mechanical Department for his time to time advice and support and also
for providing all the necessary facilities available in the Institute.
Acknowledgement will not be completed if I forget to mention special thanks to all the teaching
and non-teaching staff of Electrical Mechanical Department for rendering support directly or
indirectly.

Academic Year: 2024-25


Date-

3
ABSTRACT

This micro-project explores the computation of Fibonacci numbers using a mathematical approach
implemented in Python. Instead of relying on traditional recursive or iterative methods, the project
leverages Binet's formula, a closed-form expression derived from the golden ratio, to compute
Fibonacci numbers efficiently. By avoiding recursion or loops, the formula provides a direct
method for calculating Fibonacci numbers at any given index with high precision.

The implementation demonstrates how mathematical techniques can optimize computational


efficiency and reduce the time complexity of algorithms. The code showcases Python's ability to
handle floating-point arithmetic and mathematical operations with libraries such as math for square
roots and powers.

This project serves as an example of integrating mathematical insights into programming to


achieve concise, fast, and elegant solutions for computational problems.

4
INDEX

Sr. No Topic Page No


1 Certificate 2
2 Acknowledgement 3
3 Abstract 4
4 Introduction 6
5 Methodology 7
6 Code 8
7 Sample output 9
8 Conclusion 10

5
1. INTRODUCTION

The Fibonacci sequence is one of the most well-known mathematical series, appearing in
numerous natural patterns, mathematical studies, and computational problems. Traditionally,
Fibonacci numbers are computed using iterative or recursive algorithms, which can be
straightforward but become inefficient for large indices due to their computational overhead and
time complexity.

This micro-project focuses on implementing an alternative approach to computing Fibonacci


numbers by utilizing a mathematical formula known as Binet’s formula. This closed-form
expression provides a direct way to calculate Fibonacci numbers without the need for iterative or
recursive processes. By leveraging Python's built-in mathematical libraries, the project showcases
a concise and efficient solution for generating Fibonacci numbers.

The implementation highlights the power of combining mathematical theory with programming to
optimize computations. This report outlines the underlying theory of Binet's formula, explains its
implementation in Python, and discusses the benefits and limitations of this method compared to
traditional approaches. Through this project, we aim to demonstrate the elegance and utility of
mathematical programming in solving classical computational problems.

6
2. METHODOLOGY

2.1. Input from the User:


Ask the user to input a number n to compute the n-th Fibonacci number and the sequence.

2.2. Enhance the Formula Function:


Modify the provided function to return the Fibonacci number.

2.3. Generate Full Sequence:


Create a loop to compute all Fibonacci numbers from 1 to n using the formula function.

2.4. Display Results:


Display both the n-th Fibonacci number and the sequence.

7
3. CODE

from math import sqrt

# Function to compute n-th Fibonacci number


def nthFib(n):
res = (((1 + sqrt(5)) * n) - ((1 - sqrt(5)) * n)) / (2 ** n * sqrt(5))
return int(res)

# Main program
def fibonacci_sequence():
# Input from the user
n = int(input("Enter the value of n: "))

# Generate the Fibonacci sequence


sequence = [nthFib(i) for i in range(1, n + 1)]

# Print the results


print(f"The {n}-th Fibonacci number is: {sequence[-1]}")
print(f"The Fibonacci sequence up to {n} terms is: {sequence}")

# Driver code
if _name_ == "_main_":
fibonacci_sequence()

8
4. SAMPLE OUTPUT

Enter the value of n: 10


The 10-th Fibonacci number is: 55
The Fibonacci sequence up to 10 terms is: [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

9
5. CONCLUSION

This project successfully demonstrated an efficient and elegant approach to computing Fibonacci
numbers using a mathematical formula implemented in Python. The approach not only provides a
deeper understanding of the Fibonacci sequence but also demonstrates the utility of Python for
implementing mathematical algorithms. Future work could explore optimizing the method further
or applying similar techniques to other mathematical sequences or problems.

10

You might also like