Skip to content

Commit

Permalink
[Important] Rewrite InterpChebyshev methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed Jun 26, 2024
1 parent e108f16 commit b587c52
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 309 deletions.
6 changes: 4 additions & 2 deletions russell_lab/benches/algo_chebyshev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ fn bench_chebyshev_eval(c: &mut Criterion) {
for nn in &nns {
group.throughput(Throughput::Elements(*nn as u64));
group.bench_with_input(BenchmarkId::new("clenshaw", nn), nn, |b, &nn| {
let interp = InterpChebyshev::new_with_f(nn, xa, xb, args, f).unwrap();
let mut interp = InterpChebyshev::new(nn, xa, xb).unwrap();
interp.set_function(nn, args, f).unwrap();
b.iter(|| interp.eval((xa + xb) / 2.0).unwrap());
});
group.bench_with_input(BenchmarkId::new("trigonometric", nn), nn, |b, &nn| {
let interp = InterpChebyshev::new_with_f(nn, xa, xb, args, f).unwrap();
let mut interp = InterpChebyshev::new(nn, xa, xb).unwrap();
interp.set_function(nn, args, f).unwrap();
b.iter(|| interp.eval_using_trig((xa + xb) / 2.0).unwrap());
});
}
Expand Down
3 changes: 2 additions & 1 deletion russell_lab/examples/algo_interp_chebyshev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ fn main() -> Result<(), StrError> {
// interpolant
let degree = 10;
let args = &mut 0;
let interp = InterpChebyshev::new_with_f(degree, xa, xb, args, f)?;
let mut interp = InterpChebyshev::new(degree, xa, xb)?;
interp.set_function(degree, args, f)?;
approx_eq(interp.eval(0.0).unwrap(), 1.0, 1e-15);

// plot
Expand Down
3 changes: 2 additions & 1 deletion russell_lab/examples/algo_interp_chebyshev_adapt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ fn main() -> Result<(), StrError> {
let nn_max = 200;
let tol = 1e-8;
let args = &mut 0;
let interp = InterpChebyshev::new_adapt_f(nn_max, tol, xa, xb, args, f)?;
let mut interp = InterpChebyshev::new(nn_max, xa, xb)?;
interp.adapt_function(tol, args, f)?;
println!("N = {}", interp.get_degree());

// plot
Expand Down
5 changes: 3 additions & 2 deletions russell_lab/examples/algo_interp_chebyshev_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() -> Result<(), StrError> {
// data
let (xa, xb) = (0.0, 1.0);
let dx = xb - xa;
let uu = Vector::from(&[3.0, 0.5, -4.5, -7.0]);
let uu = Vector::from(&[-7.0, -4.5, 0.5, 3.0]);
let np = uu.dim(); // number of points
let nn = np - 1; // degree
let mut xx_dat = Vector::new(np);
Expand All @@ -17,7 +17,8 @@ fn main() -> Result<(), StrError> {
// interpolant
let nn_max = 100;
let tol = 1e-8;
let interp = InterpChebyshev::new_adapt_uu(nn_max, tol, xa, xb, uu.as_data())?;
let mut interp = InterpChebyshev::new(nn_max, xa, xb)?;
interp.adapt_data(tol, uu.as_data())?;
let nn = interp.get_degree();

// plot
Expand Down
3 changes: 2 additions & 1 deletion russell_lab/examples/algo_interp_chebyshev_noisy_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fn main() -> Result<(), StrError> {
// interpolant
let nn_max = 100;
let tol = 1e-8;
let interp = InterpChebyshev::new_adapt_uu(nn_max, tol, xa, xb, uu.as_data())?;
let mut interp = InterpChebyshev::new(nn_max, xa, xb)?;
interp.adapt_data(tol, uu.as_data())?;
let nn = interp.get_degree();

// plot
Expand Down
3 changes: 2 additions & 1 deletion russell_lab/examples/algo_multi_root_solver_cheby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fn main() -> Result<(), StrError> {
// adaptive interpolation
let nn_max = 200;
let tol = 1e-8;
let interp = InterpChebyshev::new_adapt_f(nn_max, tol, xa, xb, args, f)?;
let mut interp = InterpChebyshev::new(nn_max, xa, xb)?;
interp.adapt_function(tol, args, f)?;
let nn = interp.get_degree();
println!("N = {}", nn);

Expand Down
Loading

0 comments on commit b587c52

Please sign in to comment.