Git Product home page Git Product logo

oguzhan-baser / polynomialsolver_intervalbisection_vs_secantmethod Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 249 KB

Some common methods to find roots of non-linear equations are discussed. Interval Bisection and Secant Method are implemented and compared with each other.

License: MIT License

C++ 100.00%
polynomial-solvers interval-bisection secant-method mathematics numerical-methods root-finding

polynomialsolver_intervalbisection_vs_secantmethod's Introduction

Polynomial Solver / Root Finding (Interval Bisection vs Secant Method)

There are several approaches to find roots of a given polynomial via computer assistance with finite precisions. Some of the common techniques to deal with such problems are Interval Bisection, Broyden’s Method, Newton’s Method, Secant Method, Inverse Interpolation, Fixed-Point Iteration etc.

Each approach discussed above has several advantages/disadvantages over each other. One method may converge to a root for a given polynomial while the other method diverges. Different approaches may converge distinct roots of the polynomial. Some approaches (e.g. Interval Bisection) can be used only to solve non-linear equations with one unknown (1D) (e.g. equation ) while some approaches (e.g. Broyden’s Method) can be used to solve systems of non-linear equations or simply equation (e.g. equation ). Hence, the right approach must be chosen to reach a proper solution with efficient use of sources. Accordingly, the behaviour or rough shape of the function space should be considered before choosing and implementing one of the approaches above.

Through this simple project, it is aimed to show differences between Interval Bisection and Secant Method, in terms of use of sources such as running time. Let's take a look at these approaches first.

INTERVAL BISECTION:

The Interval Bisection approach is briefly derived from the Intermediate Value Theorem. The theorem simply implies that there exists at least one root of equation in the interval equation if equation.

There is a need for specifying the two variables, a and b, before applying Interval Bisection, and it is assumed that the condition equation holds. Next step is calculating c which is the average of a and b. Then equation is calculated as shown in the figure. The value of c is assigned to the variable whose function output has the same sign as f(c). Then the average of a and b is calculated. This iteration keeps going until the difference between values of the variables a and b becomes less than a certain threshold which will be called tolerance for our case. The tolerance value is a hyperparameter defined by the designer in order to reach the targeted precision of the output.

SECANT METHOD:

Secant Method is derived from Newton's Method. Since calculating the derivative in Newton’s Method is computationally costly, the derivative is approximated by the finite-difference here.

Two initial guesses (a and b) are inputted to polynomial function, and outputs are got. Then a straight line is drawn between these outputs. The point where this straight line intersects with the x-axis is found. This point can be calculated directly via formula . Then, this new point value is replaced with one of the initial guesses. This iteration continues to replace old points with the calculated ones until difference between the value of these points is less than a certain threshold which is specified by the designer. One step of the iteration is shown in the figure below.

These two approaches are implemented in the given main.cpp file. After creating an exe file, the following input is given: main 2 2 -7 1 -7 1.5 1.8 0.001 which stands for formula with initial guesses 1.5, 1.8 and tolerance value 0.001.

The root is calculated via two different approaches discussed above. Several polynomial functions are also given to the scripts. Finally, following results are reached:

Interval Bisection is a highly robust algorithm that certainly converges if conditions are satisfied. However, it takes a lot of time to reach the result. On the other hand, Secant Method diverges easily in most cases, yet it reaches the result faster than Interval Bisection algorithm if it converges. There is obviously a tradeoff between convergence and running time. Thus, an alternative approach which simply a mixture of those two is implemented named as Hybrid Method. For the first two iterations, a more robust approach (Interval Bisection) is run. Then, Secant Method is run until the final result is got. It is seen that the hybrid method is almost always the best of those approaches in terms of convergence and running time.

polynomialsolver_intervalbisection_vs_secantmethod's People

Contributors

oguzhan-baser avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.