CharacteristicPolynomial

Struct CharacteristicPolynomial 

Source
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: Symbol

Variable symbol (typically λ or lambda)

Implementations§

Source§

impl CharacteristicPolynomial

Source

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
);
Source

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);
Source

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λ + λ²
Source

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));
Source

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 polynomial
  • poly2 - 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);
Source

pub fn multiply( &self, other: &CharacteristicPolynomial, ) -> CharacteristicPolynomial

Multiplies two characteristic polynomials

§Arguments
  • poly1 - First polynomial
  • poly2 - 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);
Source

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

Source§

fn clone(&self) -> CharacteristicPolynomial

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CharacteristicPolynomial

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.