Skip to content

Commit

Permalink
Fix refine function calling
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed Jun 26, 2024
1 parent 6252cec commit aee0b28
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion russell_lab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Total computation time = 907ns

### Finding all roots in an interval

This example employs a Chebyshev interpolant to find all roots of a function in an interval. The method uses adaptive interpolation followed by calculating the eigenvalues of the companion matrix. These eigenvalues equal the roots of the polynomial. After that, a simple Newton polishing algorithm is applied.
This example employs a Chebyshev interpolant to find all roots of a function in an interval. The method uses adaptive interpolation followed by calculating the eigenvalues of the companion matrix. These eigenvalues equal the roots of the polynomial. After that, a simple Newton refining (polishing) algorithm is applied.

[See the code](https://github.com/cpmech/russell/tree/main/russell_lab/examples/algo_multi_root_solver_cheby.rs)

Expand Down
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 @@ -23,7 +23,7 @@ fn main() -> Result<(), StrError> {
println!("roots =\n{}", roots);
println!("f @ roots =\n{}", vec_fmt_scientific(&f_at_roots, 2));

// polish the roots
// refine/polish the roots
let mut roots_refined = roots.clone();
solver.refine(roots_refined.as_mut_data(), xa, xb, args, f)?;
let f_at_roots_refined = roots_refined.get_mapped(|x| f(x, args).unwrap());
Expand Down
12 changes: 6 additions & 6 deletions russell_lab/src/algo/root_finding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct RootFinding {
/// Default = 1e-13
pub newton_tol_zero_fx: f64,

/// Holds the maximum number of iterations for the Newton polishing
/// Holds the maximum number of iterations for the Newton refinement/polishing
///
/// Default = 15
pub newton_max_iterations: usize,
Expand Down Expand Up @@ -218,8 +218,8 @@ impl RootFinding {
/// let mut roots = solver.chebyshev(&interp)?;
/// array_approx_eq(&roots, &[-0.5, 0.5], 1e-15); // inaccurate
///
/// // polish the roots
/// solver.polish_roots_newton(&mut roots, xa, xb, args, f)?;
/// // refine/polish the roots
/// solver.refine(&mut roots, xa, xb, args, f)?;
/// array_approx_eq(&roots, &[-1.0, 1.0], 1e-15); // accurate
/// Ok(())
/// }
Expand Down Expand Up @@ -428,7 +428,7 @@ mod tests {
}

#[test]
fn polish_roots_newton_captures_errors() {
fn refine_captures_errors() {
let f = |_, _: &mut NoArgs| Ok(0.0);
let args = &mut 0;
let _ = f(0.0, args);
Expand All @@ -448,7 +448,7 @@ mod tests {
}

#[test]
fn polish_roots_newton_works() {
fn refine_works() {
// function
let f = |x, _: &mut NoArgs| Ok(x * x * x * x - 1.0);
let (xa, xb) = (-2.0, 2.0);
Expand All @@ -471,7 +471,7 @@ mod tests {
// figure
/*
graph(
"test_polish_roots_newton",
"test_root_finding_refine",
&interp,
&roots,
&roots_refined,
Expand Down

0 comments on commit aee0b28

Please sign in to comment.