Skip to content

Commit de430a9

Browse files
authored
Update README.md
1 parent 3a6ca11 commit de430a9

File tree

1 file changed

+58
-15
lines changed

1 file changed

+58
-15
lines changed

README.md

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Bisection Method Implementation in Python
1+
# Bisection Method Implementation in Python
22

33
This repository contains a Python implementation of the Bisection Method for finding roots of nonlinear equations. The code includes input validation, iteration, and termination based on the desired error or reaching the maximum number of iterations. Results are saved into an Excel file.
44

@@ -7,6 +7,12 @@ This repository contains a Python implementation of the Bisection Method for fin
77
- [Dependencies](#dependencies)
88
- [Installation](#installation)
99
- [Usage](#usage)
10+
- [Code Explanation](#code-explanation)
11+
- [Example](#example)
12+
- [Files in the Repository](#files-in-the-repository)
13+
- [Input Parameters](#input-parameters)
14+
- [Troubleshooting](#troubleshooting)
15+
- [Author](#author)
1016

1117
### Bisection Method Theory
1218
The Bisection Method is a numerical technique to find roots of a continuous function where the function changes signs over an interval. The main idea leverages the Intermediate Value Theorem, which states that if a function changes sign over an interval, it must cross zero within that interval.
@@ -31,19 +37,18 @@ pip install numpy xlwt
3137

3238
### Usage
3339
1. Clone the repository.
34-
2. Run the script using Python:
35-
36-
```sh
37-
python bisection_method.py
38-
```
39-
40-
3. Provide the required inputs when prompted:
41-
- Enter the first initial value (\( x_l \)).
42-
- Enter the second initial value (\( x_u \)).
43-
- Enter the desired percentage relative error.
44-
- Enter the number of iterations.
45-
46-
4. The script will compute the bisection method iterations and save the results in an Excel file named `LAB1.xls`.
40+
2. Ensure the script and the Excel file (`LAB1.xls`) are in the same directory.
41+
3. Run the script using Python:
42+
```sh
43+
python bisection_method.py
44+
```
45+
4. Provide the required inputs when prompted:
46+
- Enter the first initial value (\( x_l \)).
47+
- Enter the second initial value (\( x_u \)).
48+
- Enter the desired percentage relative error.
49+
- Enter the number of iterations.
50+
51+
5. The script will compute the bisection method iterations and save the results in an Excel file named `LAB1.xls`.
4752

4853
### Code Explanation
4954
The code starts by importing the necessary libraries and taking user input for the initial values, desired relative error, and number of iterations. Then, it initializes arrays to store intermediate results. The main iteration loop of the Bisection Method computes the midpoints and function values, updating the intervals as necessary, until the termination criteria are met. Finally, the results are written into an Excel sheet.
@@ -80,8 +85,46 @@ for i in range(ite):
8085
8186
The code completes by saving the final results into the Excel file `LAB1.xls`.
8287
88+
### Example
89+
Below is an example of how to use the script:
90+
91+
1. **Run the script**:
92+
```sh
93+
python bisection_method.py
94+
```
95+
96+
2. **Enter the input values**:
97+
```
98+
Enter 1st initial value: 20
99+
Enter 2nd initial value: 30
100+
Enter desired percentage relative error: 0.001
101+
Enter number of iterations: 50
102+
```
103+
104+
3. **Output**:
105+
- The script will compute the Bisection Method iterations and print intermediate results on the console.
106+
- The final results will be saved in an Excel file named `LAB1.xls`.
107+
83108
### Files in the Repository
84109
- `bisection_method.py`: The main script for performing the Bisection Method
85110
- `LAB1.xls`: Excel file generated by running the script
86111
87-
Feel free to contribute by creating issues and submitting pull requests. Happy coding!
112+
### Input Parameters
113+
The script prompts for the following input values:
114+
- Initial guess for the lower bound (`xl`).
115+
- Initial guess for the upper bound (`xu`).
116+
- Desired percentage relative error (`err`).
117+
- Number of iterations (`ite`).
118+
119+
### Troubleshooting
120+
1. **Initial Input Values**: Ensure that the initial guesses bracket the root (`f(xl) * f(xu) < 0`). If they do not, the script will print "Wrong initial input".
121+
2. **Function Evaluation**: The function `(667.38/x)*(1-math.exp(-0.146843*x))-40` is hardcoded. Modify it as needed for different functions.
122+
3. **Excel File Creation**: Ensure you have write permissions in the directory where the script is run to save the Excel file.
123+
4. **Python Version**: This script is compatible with Python 3. Ensure you have Python 3 installed.
124+
125+
## Author
126+
Script created by sudipto3331.
127+
128+
---
129+
130+
This documentation should guide you through understanding, installing, and using the Bisection Method script. For further issues or feature requests, please open an issue in the repository on GitHub. Feel free to contribute by creating issues and submitting pull requests. Happy coding!

0 commit comments

Comments
 (0)