pub struct CharacteristicPolynomial {
pub coefficients: Vec<Expression>,
pub variable: Symbol,
}Expand description
Characteristic polynomial of a matrix
Represents the polynomial det(A - λI) where A is a matrix and λ is a variable. The roots of this polynomial are the eigenvalues of the matrix.
§Mathematical Definition
For an n×n matrix A, the characteristic polynomial is: $$p(\lambda) = \det(A - \lambda I)$$
This expands to a polynomial of degree n: $$p(\lambda) = c_0 + c_1\lambda + c_2\lambda^2 + \cdots + c_n\lambda^n$$
§Properties
- Degree equals matrix dimension
- Coefficients are polynomial expressions in matrix entries
- Roots (eigenvalues) may be real or complex
- Leading coefficient is (-1)^n
- Constant term is det(A)
§Examples
use mathhook_core::{expr, symbol, Expression};
use mathhook_core::matrices::eigenvalues::characteristic::CharacteristicPolynomial;
let lambda = symbol!(lambda);
// 2×2 matrix characteristic polynomial: λ² - trace·λ + det
let poly = CharacteristicPolynomial::new(
vec![
Expression::add(vec![
expr!(a * d),
Expression::mul(vec![expr!(-1), expr!(b * c)]),
]), // det(A)
Expression::mul(vec![expr!(-1), expr!(a + d)]), // -trace(A)
expr!(1), // leading coefficient
],
lambda.clone()
);Fields§
§coefficients: Vec<Expression>Coefficients of the polynomial [c₀, c₁, c₂, …, cₙ] where p(λ) = c₀ + c₁λ + c₂λ² + … + cₙλⁿ
variable: SymbolVariable symbol (typically λ or lambda)
Implementations§
Source§impl CharacteristicPolynomial
impl CharacteristicPolynomial
Sourcepub fn new(coefficients: Vec<Expression>, variable: Symbol) -> Self
pub fn new(coefficients: Vec<Expression>, variable: Symbol) -> Self
Creates new characteristic polynomial
§Arguments
coefficients- Polynomial coefficients [c₀, c₁, …, cₙ]variable- Variable symbol (typically λ)
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::matrices::eigenvalues::characteristic::CharacteristicPolynomial;
let lambda = symbol!(lambda);
let poly = CharacteristicPolynomial::new(
vec![expr!(6), expr!(-5), expr!(1)], // λ² - 5λ + 6
lambda
);Sourcepub fn degree(&self) -> usize
pub fn degree(&self) -> usize
Returns the degree of the polynomial
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::matrices::eigenvalues::characteristic::CharacteristicPolynomial;
let lambda = symbol!(lambda);
let poly = CharacteristicPolynomial::new(
vec![expr!(1), expr!(2), expr!(3)],
lambda
);
assert_eq!(poly.degree(), 2);Sourcepub fn to_expression(&self) -> Expression
pub fn to_expression(&self) -> Expression
Converts polynomial to expression form
Returns: c₀ + c₁λ + c₂λ² + … + cₙλⁿ
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::matrices::eigenvalues::characteristic::CharacteristicPolynomial;
let lambda = symbol!(lambda);
let poly = CharacteristicPolynomial::new(
vec![expr!(6), expr!(-5), expr!(1)],
lambda.clone()
);
let expr = poly.to_expression();
// Represents: 6 - 5λ + λ²Sourcepub fn evaluate(&self, value: &Expression) -> Expression
pub fn evaluate(&self, value: &Expression) -> Expression
Evaluates polynomial at given value
Uses Horner’s method for efficient evaluation.
§Arguments
value- Value to substitute for variable
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::matrices::eigenvalues::characteristic::CharacteristicPolynomial;
let lambda = symbol!(lambda);
let poly = CharacteristicPolynomial::new(
vec![expr!(6), expr!(-5), expr!(1)], // λ² - 5λ + 6
lambda
);
let result = poly.evaluate(&expr!(2)); // 2² - 5(2) + 6 = 0
assert_eq!(result, expr!(0));Sourcepub fn add(&self, other: &CharacteristicPolynomial) -> CharacteristicPolynomial
pub fn add(&self, other: &CharacteristicPolynomial) -> CharacteristicPolynomial
Adds two characteristic polynomials
Note: This is polynomial addition, not matrix addition. Both polynomials must use the same variable.
§Arguments
poly1- First polynomialpoly2- Second polynomial
§Returns
Sum of the two polynomials
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::matrices::eigenvalues::characteristic::{CharacteristicPolynomial, CharacteristicPolynomialBuilder};
let lambda = symbol!(lambda);
let builder = CharacteristicPolynomialBuilder;
let poly1 = CharacteristicPolynomial::new(
vec![expr!(1), expr!(2)], // 1 + 2λ
lambda.clone()
);
let poly2 = CharacteristicPolynomial::new(
vec![expr!(3), expr!(4)], // 3 + 4λ
lambda.clone()
);
let sum = builder.add(&poly1, &poly2); // 4 + 6λ
assert_eq!(sum.coefficients.len(), 2);Sourcepub fn multiply(
&self,
other: &CharacteristicPolynomial,
) -> CharacteristicPolynomial
pub fn multiply( &self, other: &CharacteristicPolynomial, ) -> CharacteristicPolynomial
Multiplies two characteristic polynomials
§Arguments
poly1- First polynomialpoly2- Second polynomial
§Returns
Product of the two polynomials
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::matrices::eigenvalues::characteristic::CharacteristicPolynomial;
let lambda = symbol!(lambda);
let poly1 = CharacteristicPolynomial::new(
vec![expr!(1), expr!(1)], // 1 + λ
lambda.clone()
);
let poly2 = CharacteristicPolynomial::new(
vec![expr!(2), expr!(1)], // 2 + λ
lambda.clone()
);
let product = poly1.multiply(&poly2); // 2 + 3λ + λ²
assert_eq!(product.degree(), 2);Sourcepub fn format(&self) -> String
pub fn format(&self) -> String
Formats polynomial as human-readable string
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::matrices::eigenvalues::characteristic::CharacteristicPolynomial;
let lambda = symbol!(lambda);
let poly = CharacteristicPolynomial::new(
vec![expr!(6), expr!(-5), expr!(1)],
lambda
);
let formatted = poly.format();
// Output: "6 + (-5)·λ + λ²"Trait Implementations§
Source§impl Clone for CharacteristicPolynomial
impl Clone for CharacteristicPolynomial
Source§fn clone(&self) -> CharacteristicPolynomial
fn clone(&self) -> CharacteristicPolynomial
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CharacteristicPolynomial
impl RefUnwindSafe for CharacteristicPolynomial
impl Send for CharacteristicPolynomial
impl Sync for CharacteristicPolynomial
impl Unpin for CharacteristicPolynomial
impl UnwindSafe for CharacteristicPolynomial
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more