module GSL::MultiRoot

Overview

This module implements Multidimensional Root-Finding

Usage examples:

a = 1.0
b = 10.0
result, root_value = GSL::MultiRoot.find_root(initial: GSL::Vector.new([-10.0, -5.0]), eps_f: 1e-7, max_iter: 1000) do |x, y|
  y[0] = a * (1 - x[0])
  y[1] = b * (x[1] - x[0] * x[0])
end
result.should eq GSL::Result::Success
root_value.should eq GSL::Vector.new([1.0, 1.0])
a = 1.0
b = 10.0
result, root_value = GSL::MultiRoot.find_root_fdf(initial: GSL::Vector.new([-10.0, -5.0]), eps_f: 1e-7, max_iter: 1000) do |x, y, j|
  if y
    y[0] = a * (1 - x[0])
    y[1] = b * (x[1] - x[0] * x[0])
  end
  if j
    j[0, 0] = -a
    j[0, 1] = 0
    j[1, 0] = -2 * b * x[0]
    j[1, 1] = b
  end
end
result.should eq GSL::Result::Success
root_value.should eq GSL::Vector.new([1.0, 1.0])

Defined in:

gsl/maths/optimization/multiroot.cr

Class Method Summary

Class Method Detail

def self.find_root(f : GSL::MultiRootFunction, initial : GSL::Vector, eps_x : Float64 = 1e-6, eps_f : Float64 = 1e-9, *, algorithm : GSL::MultiRoot::AlgorithmF = GSL::MultiRoot::AlgorithmF::HybridScaled, max_iter = 10000) #

High-level interface to root finder.

  • f - function to minimize
  • initial - initial guess
  • eps_x - tolerance by x. Iterations terminates when all components of dx are <= eps_x
  • eps_f - tolerance by f. Iterations terminates when all components of f are <= eps_x
  • algorithm - root finding algorithm to be used
  • max_iter - maximum number of iterations

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(initial : GSL::Vector, eps_x : Float64 = 1e-6, eps_f : Float64 = 1e-9, *, algorithm : GSL::MultiRoot::AlgorithmF = GSL::MultiRoot::AlgorithmF::HybridScaled, max_iter = 10000, &f : GSL::MultiRootFunction) #

[View source]
def self.find_root_fdf(f : GSL::MultiRootFunctionFDF, initial : GSL::Vector, eps_x : Float64 = 1e-6, eps_f : Float64 = 1e-9, *, algorithm : GSL::MultiRoot::AlgorithmFDF = GSL::MultiRoot::AlgorithmF::HybridJScaled, max_iter = 10000) #

High-level interface to root finder.

  • f - function to minimize
  • initial - initial guess
  • eps_x - tolerance by x. Iterations terminates when all components of dx are <= eps_x
  • eps_f - tolerance by f. Iterations terminates when all components of f are <= eps_x
  • algorithm - root finding algorithm to be used
  • max_iter - maximum number of iterations

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_fdf(initial : GSL::Vector, eps_x : Float64 = 1e-6, eps_f : Float64 = 1e-9, *, algorithm : GSL::MultiRoot::AlgorithmFDF = GSL::MultiRoot::AlgorithmFDF::HybridScaled, max_iter = 10000, &f : GSL::MultiRootFunctionFDF) #

[View source]