Root Finder


November 25, 2019

Application built with Java.

Application and source code available on GitHub.

Root Finder was part of the Computer Algorithms and Modelling course at University. The objective of the course was to introduce us to Algorithms and Data Structures to develop more complex programs.

The requirement was to produce a program that allows the finding of a root of given functions with the option to choose different root finding techniques while using different data structures. The funcitons to be included were:

  1. f(x) = x - x2
  2. f(x) = ln(x+1) + 1
  3. f(x) = ex - 3x

And the numerical methods to be included:

  1. Newton-Raphson (using LinkedList)
  2. Secant (using Array)
  3. Bisection (using Array)
  4. False Position (using LinkedList)

I started by writing code where everything was hard-coded, giving me an idea of what components I could extract and generalize. It was apparent I needed to turn functions and numerical methods into their own classes.

For the functions, I first created an abstract class containing methods I would need to call: computeY(double x) and computeYderivative(double x). The first is used to calculate the Y value given an X coordinate, with its body being the function (e.g. for quadratic the body would be return x-x*x), the second would return the derivative of the function (i.e. return 1 - 2x for the previous example). I would then initialize the concrete class for each of the functions above.

For numerical methods, I could not have created abstract classes since I was to deal with different data types. My solution was to create methods for each of the numerical methods and store them in a single class. The constructor would take the Function, starting point(s) and degree of accuracy as parameters, with the body being the algorithm for each numerical method.

An additional requirement was to include both graphical and tabular representation of the iterations. The tabular view was easily created by using a JTable and by passing the values of the LinkedList or Array into a TableModel. For the graphical view, I used a library called XChart, and included this as a Maven dependancy.

The contents of this course have been very insightful on both Abstract Data Types and performance of algorithms. This helped me on extending my knowledge of programming concepts as well as revise content from last year’s Object-Oriented Programming course. More importantly, the problem solving of the coursework taught me on the importance of planning as well as prototyping to understand the problem.