Skip to content

Commit

Permalink
hermite and bessel polynomials added
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrage committed Oct 30, 2024
1 parent 8d7816b commit d84cc92
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/structure/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,49 @@ pub fn chebyshev_polynomial(n: usize, kind: SpecialKind) -> Polynomial {
}
}
}

/// Hermite Polynomial
///
/// # Description
/// Generate `n`-th order Hermite polynomial. The physics convention
/// H_n(x) = (-1)^n e^{x^2}\frac{d^n}{dx^n}e^{-x^2} is used.
pub fn hermite_polynomial(n: usize) -> Polynomial {
let mut prev = Polynomial::new(vec![1f64]); // 1
let mut curr = Polynomial::new(vec![2f64, 0f64]); // 2x

match n {
0 => prev,
1 => curr,
_ => {
for idx in 1 .. n {
let k = idx as f64;
std::mem::swap(&mut prev, &mut curr);
curr = poly(vec![2f64, 0f64]) * prev.clone() - 2.0*k*curr;
}
curr
}
}
}

/// Bessel Polynomial
///
/// # Description
/// Generate `n`-th order Bessel polynomial. Definition according to
/// Krall and Fink (1949).
pub fn bessel_polynomial(n: usize) -> Polynomial {
let mut prev = Polynomial::new(vec![1f64]); // 1
let mut curr = Polynomial::new(vec![1f64, 1f64]); // x + 1

match n {
0 => prev,
1 => curr,
_ => {
for idx in 1 .. n {
let k = idx as f64;
std::mem::swap(&mut prev, &mut curr);
curr = (2.0*k+1.0) * poly(vec![1f64, 0f64]) * prev.clone() + curr;
}
curr
}
}
}

0 comments on commit d84cc92

Please sign in to comment.