module GSL::Roots

Overview

This module implements One Dimensional Root-Finding

Usage examples:

# find root inside a range.
xm = GSL::Roots.find_root(0, 3) do |x|
  Math.cos(x) - 0.5
end
xm.should be_close(Math::PI / 3, 1e-9)
# polish root from initial guess. This method requires function and its derivative
root = GSL::Roots.polish_root(10, x_possible: (0.0..)) do |x|
  f = x*x*x - 125
  df = 3*x*x
  {f, df}
end
root.should be_close 5, 1e-9

Defined in:

gsl/maths/optimization/roots.cr

Class Method Summary

Class Method Detail

def self.find_root(f : GSL::Function, x_lower : Float64, x_upper : Float64, eps : Float64 = 1e-9, *, algorithm : GSL::Roots::TypeBracketing = GSL::Roots::TypeBracketing::BrentDekker, max_iter = 10000) #

High-level interface to root finder. Finds root of function f between x_lower and x_upper,

due to nature of used algorithms, signs of function in x_lower and x_upper must differ

  • algorithm - root bracketing algorithm to be used

returns {result, x_root}

  • result (type GSL::Result) represents result of minimization
  • x_root - value of root on last iteration

[View source]
def self.find_root(x_lower : Float64, x_upper : Float64, eps : Float64 = 1e-9, *, algorithm : GSL::Roots::TypeBracketing = GSL::Roots::TypeBracketing::BrentDekker, max_iter = 10000, &f : GSL::Function) #

[View source]
def self.polish_root(f : GSL::FunctionFDF, initial_guess : Float64, eps : Float64 = 1e-9, *, x_possible : Range(Float64 | Nil, Float64 | Nil) | Nil = nil, algorithm : GSL::Roots::TypePolishing = GSL::Roots::TypePolishing::Steffenson, max_iter = 10000) #

High-level interface to root polishing. Finds root of function f near initial_guess

  • algorithm - root bracketing algorithm to be used

returns {result, x_root}

  • result (type GSL::Result) represents result of minimization
  • x_root - value of root on last iteration

[View source]
def self.polish_root(initial_guess : Float64, eps : Float64 = 1e-9, *, x_possible : Range(Float64 | Nil, Float64 | Nil) | Nil = nil, algorithm : GSL::Roots::TypePolishing = GSL::Roots::TypePolishing::Steffenson, max_iter = 10000, &f : GSL::FunctionFDF) #

[View source]