Coder Social home page Coder Social logo

roots's Introduction

Library of well known algorithms for numerical root finding.

LicenseBuild StatusCrates.io

Features

Usage

extern crate roots;
use roots::Roots;
use roots::find_roots_cubic;
use roots::find_root_brent;
use roots::find_root_secant;

// Find the root of a complex function in the area determined by a simpler polynom
fn find_solution<F>(enormous_function: F, root_area_polynom:(f64,f64,f64,f64)) -> Option<f64>
  where F: Fn(f64) -> f64
{
  // de-structure polynom coefficients
  match root_area_polynom {
    (a3,a2,a1,a0) => {
      // Find root area by solving the polynom
      match find_roots_cubic(a3,a2,a1,a0) {
        // Try to find the root by one of iterative methods
        Roots::Three(roots) => {
          // Three roots found, normal case
          find_root_brent(roots[0],roots[2],enormous_function, &mut 1e-8f64).ok()
        },
        Roots::Two(roots) => {
          // Two roots found, High precision required
          find_root_brent(roots[0],roots[1],enormous_function,&mut 1e-15f64).ok()
        },
        Roots::One(roots) => {
          // One root found, Low precision is enough
          find_root_secant(roots[0]-1f64,roots[0]+1f64,enormous_function,&mut 1e-3f64).ok()
        },
        _ => None,
      }
    },
    _ => None,
  }
}

roots's People

Contributors

vorot avatar milibopp avatar sebedard13 avatar ralith avatar danielhstahl avatar j-f-liu avatar jingnanshi 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.