0.0
No commit activity in last 3 years
No release in over 3 years
Newton's method works best when you have a reasonable first guess, while bisection is a better choice when your first guess may be far away (or near a zero slope).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.12
~> 5.0
~> 10.0
 Project Readme

RootSolver

root_solver will solve for a root of a mathematical function using a bisection method to get close then switching over to Newton's method to hone in.

Installation

Add this line to your application's Gemfile:

gem 'root_solver'

And then execute:

$ bundle

Or install it yourself as:

$ gem install root_solver

Usage

root_solver expects a callable (proc, lambda, PORO responding to call). The callable should take one argument, our x, and the callable should evaluate our function at x. Example callable:

f    = Proc.new { |x| x ** 2 - 10 } # Function for which we wish to find roots
low  = -5															# An educated guess for the lower limit
high = 5															# An educated guess for the upper limit
tol  = 1e-3														# How accurate do we want to be

RootSolver::BisectionNewton.new(f, low, 0, tol).solve
=> -3.1622776375625614
RootSolver::BisectionNewton.new(f, 0, high, tol).solve
=> 3.1622813514478687

# If there are multiple roots between low and high, root_solver will find one
RootSolver::BisectionNewton.new(f, low, high, tol).solve
=> 3.1622813514478687

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/teamairship/root_solver.