coefficient_at

Function coefficient_at 

Source
pub fn coefficient_at(
    expr: &Expression,
    var: &Symbol,
    degree: i64,
) -> Expression
Expand description

Get the coefficient at a specific degree

§Arguments

  • expr - The polynomial expression
  • var - The variable
  • degree - The degree to extract coefficient for

§Returns

The coefficient at the specified degree, or 0 if not present

§Examples

use mathhook_core::core::polynomial::coefficient_at;
use mathhook_core::{expr, symbol};

let x = symbol!(x);
let poly = expr!((3 * (x ^ 2)) + (2 * x) + 1);

let c2 = coefficient_at(&poly, &x, 2);  // Returns 3
let c1 = coefficient_at(&poly, &x, 1);  // Returns 2
let c0 = coefficient_at(&poly, &x, 0);  // Returns 1