You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-15Lines changed: 58 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
##Bisection Method Implementation in Python
1
+
# Bisection Method Implementation in Python
2
2
3
3
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.
4
4
@@ -7,6 +7,12 @@ This repository contains a Python implementation of the Bisection Method for fin
7
7
-[Dependencies](#dependencies)
8
8
-[Installation](#installation)
9
9
-[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)
10
16
11
17
### Bisection Method Theory
12
18
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
31
37
32
38
### Usage
33
39
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`.
47
52
48
53
### Code Explanation
49
54
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 functionvalues, 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):
80
85
81
86
The code completes by saving the final results into the Excel file `LAB1.xls`.
82
87
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
+
83
108
### Files in the Repository
84
109
- `bisection_method.py`: The main script for performing the Bisection Method
85
110
- `LAB1.xls`: Excel file generated by running the script
86
111
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