Skip to content

Commit

Permalink
Rename cheby_find to chebyshev in RootFinding
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed Jun 26, 2024
1 parent f6d752c commit 684fd15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion russell_lab/examples/algo_multi_root_solver_cheby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() -> Result<(), StrError> {

// find all roots in the interval
let solver = RootFinding::new();
let roots = Vector::from(&solver.cheby_find(&interp)?);
let roots = Vector::from(&solver.chebyshev(&interp)?);
let f_at_roots = roots.get_mapped(|x| f(x, args).unwrap());
println!("roots =\n{}", roots);
println!("f @ roots =\n{}", print_vec_exp(&f_at_roots));
Expand Down
22 changes: 11 additions & 11 deletions russell_lab/src/algo/root_finding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ impl RootFinding {
///
/// // find all roots in the interval
/// let mut solver = RootFinding::new();
/// let roots = solver.cheby_find(&interp)?;
/// let roots = solver.chebyshev(&interp)?;
/// array_approx_eq(&roots, &[-1.0, 1.0], 1e-15);
/// Ok(())
/// }
/// ```
pub fn cheby_find(&self, interp: &InterpChebyshev) -> Result<Vec<f64>, StrError> {
pub fn chebyshev(&self, interp: &InterpChebyshev) -> Result<Vec<f64>, StrError> {
// check
if !interp.is_ready() {
return Err("the interpolant must initialized first");
Expand Down Expand Up @@ -215,7 +215,7 @@ impl RootFinding {
///
/// // find all roots in the interval
/// let mut solver = RootFinding::new();
/// let mut roots = solver.cheby_find(&interp)?;
/// let mut roots = solver.chebyshev(&interp)?;
/// array_approx_eq(&roots, &[-0.5, 0.5], 1e-15); // inaccurate
///
/// // polish the roots
Expand Down Expand Up @@ -375,7 +375,7 @@ mod tests {
let interp = InterpChebyshev::new(nn, xa, xb).unwrap();
let solver = RootFinding::new();
assert_eq!(
solver.cheby_find(&interp).err(),
solver.chebyshev(&interp).err(),
Some("the interpolant must initialized first")
);
}
Expand All @@ -390,7 +390,7 @@ mod tests {
interp.set_function(nn, args, f).unwrap();
let solver = RootFinding::new();
assert_eq!(
solver.cheby_find(&interp).err(),
solver.chebyshev(&interp).err(),
Some("the trailing Chebyshev coefficient vanishes; try a smaller degree N")
);
}
Expand All @@ -409,7 +409,7 @@ mod tests {

// find roots
let solver = RootFinding::new();
let roots_unpolished = solver.cheby_find(&interp).unwrap();
let roots_unpolished = solver.chebyshev(&interp).unwrap();
let mut roots_polished = roots_unpolished.clone();
solver
.polish_roots_newton(&mut roots_polished, xa, xb, args, f)
Expand Down Expand Up @@ -470,7 +470,7 @@ mod tests {

// find roots
let solver = RootFinding::new();
let roots_unpolished = solver.cheby_find(&interp).unwrap();
let roots_unpolished = solver.chebyshev(&interp).unwrap();
let mut roots_polished = roots_unpolished.clone();
solver
.polish_roots_newton(&mut roots_polished, xa, xb, args, f)
Expand Down Expand Up @@ -511,7 +511,7 @@ mod tests {
let mut interp = InterpChebyshev::new(nn_max, xa, xb).unwrap();
interp.adapt_function(tol, args, test.f).unwrap();
let solver = RootFinding::new();
let roots_unpolished = solver.cheby_find(&interp).unwrap();
let roots_unpolished = solver.chebyshev(&interp).unwrap();
let mut roots_polished = roots_unpolished.clone();
solver
.polish_roots_newton(&mut roots_polished, xa, xb, args, test.f)
Expand Down Expand Up @@ -569,7 +569,7 @@ mod tests {

// find all roots in the interval
let solver = RootFinding::new();
let roots = &solver.cheby_find(&interp).unwrap();
let roots = &solver.chebyshev(&interp).unwrap();
let nroot = roots.len();
assert_eq!(nroot, 0)
}
Expand All @@ -588,7 +588,7 @@ mod tests {

// find all roots in the interval
let solver = RootFinding::new();
let roots = &solver.cheby_find(&interp).unwrap();
let roots = &solver.chebyshev(&interp).unwrap();
let nroot = roots.len();
assert_eq!(nroot, 0)
}
Expand All @@ -615,7 +615,7 @@ mod tests {

// find all roots in the interval
let solver = RootFinding::new();
let roots = solver.cheby_find(&interp).unwrap();
let roots = solver.chebyshev(&interp).unwrap();
let nroot = roots.len();
assert_eq!(nroot, 1);
approx_eq(roots[0], 0.7, 1e-15);
Expand Down

0 comments on commit 684fd15

Please sign in to comment.