Roots
Library of well known algorithms for numerical root finding.
Install / Use
/learn @vorot/RootsREADME
Library of well known algorithms for numerical root finding.
Features
- Iterative approximation:
- Newton-Raphson method
- Secant method
- Regula falsi method (with Illinois modification)
- Brent-Dekker method
- Inverse quadratic approximation
- Recursive Sturm's method
- Solving polynomial equations
- Linear equation (editors' choice)
- Quadratic equation
- Cubic equation
- Quartic equation
- Eigenvalues method for higher-degree polynomials
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,
}
}
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
