This program implements four numerical methods for root-finding:
- Bisection Method
- Newton-Raphson Method
- Secant Method
- False-Position Method
The program ensures solutions converge within a given tolerance and detects divergent or slow-converging solutions.
This program is implemented in Java using a single main file:
- Main.java - Handles user input, applies root-finding methods, and exports results.
The user provides:
- Starting values for each method.
- Error tolerance (ea < 1%).
- Maximum iterations (100 iterations max).
The program evaluates roots for two functions: (a) f(x) = 2x³ – 11.7x² + 17.7x – 5
- This function has three positive roots in the interval [0,4]. (b) f(x) = x + 10 – x cosh(50/x)
- The root lies in the interval [120,130].
- Root estimates for each method at each iteration.
- Approximate relative percent error for each method.
- Final root value once convergence is reached or after 100 iterations.
- Exports error values for plotting.
Please choose the first starting value for the methods to use on function 1: 0
Please choose the second starting value for the methods to use on function 1: 4
The program applies all four methods to find the roots.
Relative error array exported to bisectFunction1_R34.txt
Relative error array exported to falsePosFunction1_R34.txt
Relative error array exported to newtonRaFunction1_R34.txt
Relative error array exported to secantFunction1_R34.txt
If the solution does not converge within 100 iterations, the program displays:
Sorry solution did not converge to desired relative percent error within 100 iterations.
Please choose the first starting value for the methods to use on function 2: 1
Please choose the second starting value for the methods to use on function 2: 3
The program applies all four methods to find the roots.
Relative error array exported to bisectFunction1.txt
Relative error array exported to falsePosFunction1.txt
Relative error array exported to newtonRaFunction1.txt
Relative error array exported to secantFunction1.txt
If the solution does not converge within 100 iterations, the program displays:
Sorry solution did not converge to desired relative percent error within 100 iterations.
The program exports error values to text files, which can be plotted using Google Sheets, Excel, Python, or MATLAB.
bisectFunction1_R34.txt
falsePosFunction1_R34.txt
newtonRaFunction1_R34.txt
secantFunction1_R34.txt
bisectFunction1.txt
falsePosFunction1.txt
newtonRaFunction1.txt
secantFunction1.txt
Each file contains iteration vs. relative percent error, which can be plotted with:
- Logarithmic scale of error values.
- Handles user input for starting values.
- Implements all four root-finding methods.
- Checks for convergence and stops if error criteria are met.
- Exports iteration data for visualization.
- Compile the program:
javac Main.java
- Run the program:
java Main
- Follow the prompts to input starting values.
- View the step-by-step solution and final computed results.
- Plot the error data using external software.