| 1 | // Copyright (c) 2015, Mikhail Vorotilov |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, this |
| 8 | // list of conditions and the following disclaimer. |
| 9 | // |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | // this list of conditions and the following disclaimer in the documentation |
| 12 | // and/or other materials provided with the distribution. |
| 13 | // |
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 18 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 20 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 21 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 22 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | |
| 25 | //#![crate_id = "roots"] |
| 26 | #![crate_type = "lib"] |
| 27 | |
| 28 | //! A set of functions to find real roots of numerical equations. |
| 29 | //! |
| 30 | //! This crate contains various algorithms for numerical and analytical solving |
| 31 | //! of 1-variable equations like f(x)=0. Only real roots are calculated. |
| 32 | //! Multiple (double etc.) roots are considered as one root. |
| 33 | //! |
| 34 | //! # Use |
| 35 | //! |
| 36 | //! Functions find_root_* try to find a root of any given closure function by |
| 37 | //! iterative approximations. Conditions for success/failure can be customized |
| 38 | //! by implementing the Convergency trait. |
| 39 | //! Functions find_roots_* return all roots of several simple equations at once. |
| 40 | |
| 41 | #[cfg(test)] |
| 42 | macro_rules! assert_float_eqrust-analyzer cargo roots 0.0.8 assert_float_eq!( |
| 43 | ($precision:expr, $given:expr , $expected:expr) => ({ |
| 44 | match (&($precision), &($given), &($expected)) { |
| 45 | (precision_val, given_val, expected_val) => { |
| 46 | let diff = given_val-expected_val; |
| 47 | if diff.abs() > precision_val.abs() { |
| 48 | panic!("floats are not the same: (`{}`: `{:.15e}`, expected: `{:.15e}`, precision: `{:.15e}`, delta: `{:.15e}`)", stringify!($given), *given_val, *expected_val, *precision_val, diff ) |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | }) |
| 53 | ); |
| 54 | |
| 55 | #[cfg(test)] |
| 56 | macro_rules! assert_float_array_eqrust-analyzer cargo roots 0.0.8 assert_float_array_eq!( |
| 57 | ($precision:expr, $given:expr , $expected:expr) => ({ |
| 58 | match (&($precision), &($given), &($expected)) { |
| 59 | (precision_val, given_val, expected_val) => { |
| 60 | assert_eq!(given_val.len(),expected_val.len()); |
| 61 | for i in 0..given_val.len() { |
| 62 | assert_float_eq!(precision_val,given_val[i],expected_val[i]); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | }) |
| 67 | ); |
| 68 | |
| 69 | mod analyticalrust-analyzer cargo roots 0.0.8 analytical/; |
| 70 | mod floatrust-analyzer cargo roots 0.0.8 float/; |
| 71 | mod numericalrust-analyzer cargo roots 0.0.8 numerical/; |
| 72 | |
| 73 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::floatrust-analyzer cargo roots 0.0.8 float/::FloatTyperust-analyzer cargo roots 0.0.8 float/FloatType#; |
| 74 | |
| 75 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::biquadraticrust-analyzer cargo roots 0.0.8 analytical/biquadratic/::find_roots_biquadraticrust-analyzer cargo roots 0.0.8 analytical/biquadratic/find_roots_biquadratic().; |
| 76 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::cubicrust-analyzer cargo roots 0.0.8 analytical/cubic/::find_roots_cubicrust-analyzer cargo roots 0.0.8 analytical/cubic/find_roots_cubic().; |
| 77 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::cubic_depressedrust-analyzer cargo roots 0.0.8 analytical/cubic_depressed/::find_roots_cubic_depressedrust-analyzer cargo roots 0.0.8 analytical/cubic_depressed/find_roots_cubic_depressed().; |
| 78 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::cubic_normalizedrust-analyzer cargo roots 0.0.8 analytical/cubic_normalized/::find_roots_cubic_normalizedrust-analyzer cargo roots 0.0.8 analytical/cubic_normalized/find_roots_cubic_normalized().; |
| 79 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::linearrust-analyzer cargo roots 0.0.8 analytical/linear/::find_roots_linearrust-analyzer cargo roots 0.0.8 analytical/linear/find_roots_linear().; |
| 80 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::quadraticrust-analyzer cargo roots 0.0.8 analytical/quadratic/::find_roots_quadraticrust-analyzer cargo roots 0.0.8 analytical/quadratic/find_roots_quadratic().; |
| 81 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::quarticrust-analyzer cargo roots 0.0.8 analytical/quartic/::find_roots_quarticrust-analyzer cargo roots 0.0.8 analytical/quartic/find_roots_quartic().; |
| 82 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::quartic_depressedrust-analyzer cargo roots 0.0.8 analytical/quartic_depressed/::find_roots_quartic_depressedrust-analyzer cargo roots 0.0.8 analytical/quartic_depressed/find_roots_quartic_depressed().; |
| 83 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::analyticalrust-analyzer cargo roots 0.0.8 analytical/::rootsrust-analyzer cargo roots 0.0.8 analytical/roots/::Rootsrust-analyzer cargo roots 0.0.8 analytical/roots/Roots#; |
| 84 | |
| 85 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::brentrust-analyzer cargo roots 0.0.8 numerical/brent/::find_root_brentrust-analyzer cargo roots 0.0.8 numerical/brent/find_root_brent().; |
| 86 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::debug_convergencyrust-analyzer cargo roots 0.0.8 numerical/debug_convergency/::DebugConvergencyrust-analyzer cargo roots 0.0.8 numerical/debug_convergency/DebugConvergency#; |
| 87 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::eigenrust-analyzer cargo roots 0.0.8 numerical/eigen/::find_roots_eigenrust-analyzer cargo roots 0.0.8 numerical/eigen/find_roots_eigen().; |
| 88 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::inverse_quadraticrust-analyzer cargo roots 0.0.8 numerical/inverse_quadratic/::find_root_inverse_quadraticrust-analyzer cargo roots 0.0.8 numerical/inverse_quadratic/find_root_inverse_quadratic().; |
| 89 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::inverse_quadraticrust-analyzer cargo roots 0.0.8 numerical/inverse_quadratic/::Parabolarust-analyzer cargo roots 0.0.8 numerical/inverse_quadratic/Parabola#; |
| 90 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::newton_raphsonrust-analyzer cargo roots 0.0.8 numerical/newton_raphson/::find_root_newton_raphsonrust-analyzer cargo roots 0.0.8 numerical/newton_raphson/find_root_newton_raphson().; |
| 91 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::polynomrust-analyzer cargo roots 0.0.8 numerical/polynom/::find_roots_sturmrust-analyzer cargo roots 0.0.8 numerical/polynom/find_roots_sturm().; |
| 92 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::regula_falsirust-analyzer cargo roots 0.0.8 numerical/regula_falsi/::find_root_regula_falsirust-analyzer cargo roots 0.0.8 numerical/regula_falsi/find_root_regula_falsi().; |
| 93 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::secantrust-analyzer cargo roots 0.0.8 numerical/secant/::find_root_secantrust-analyzer cargo roots 0.0.8 numerical/secant/find_root_secant().; |
| 94 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::simple_convergencyrust-analyzer cargo roots 0.0.8 numerical/simple_convergency/::SimpleConvergencyrust-analyzer cargo roots 0.0.8 numerical/simple_convergency/SimpleConvergency#; |
| 95 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::Convergencyrust-analyzer cargo roots 0.0.8 numerical/Convergency#; |
| 96 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::Intervalrust-analyzer cargo roots 0.0.8 numerical/Interval#; |
| 97 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::Samplerust-analyzer cargo roots 0.0.8 numerical/Sample#; |
| 98 | pub use selfrust-analyzer cargo roots 0.0.8 crate/::numericalrust-analyzer cargo roots 0.0.8 numerical/::SearchErrorrust-analyzer cargo roots 0.0.8 numerical/SearchError#; |