pub struct Rf<T> { /* private fields */ }
Expand description

Rational function

Implementations§

source§

impl<T: Clone + PartialEq> Rf<T>

Implementation of rational function methods

source

pub fn inv_mut(&mut self)

Compute the reciprocal of a rational function in place.

source§

impl<T> Rf<T>where T: Clone + PartialEq + Zero,

source

pub fn new<R, S>(num: R, den: S) -> Selfwhere R: AsRef<[T]>, S: AsRef<[T]>,

Create a new rational function given its numerator and denominator

Arguments
  • num - Rational function numerator
  • den - Rational function denominator
Example
use automatica::Rf;
let rf = Rf::new([1., 2.], [-4., 6., -2.]);
source

pub fn num(&self) -> impl Polynomial<T>

Extract rational function numerator

Example
use automatica::{Polynomial, Rf};
let num = [1., 2.];
let rf = Rf::new(num.clone(), [-4., 6., -2.]);
assert_eq!(num, rf.num().as_slice());
source

pub fn den(&self) -> impl Polynomial<T>

Extract rational function denominator

Example
use automatica::{Polynomial, Rf};
let den = [-4., 6., -2.];
let rf = Rf::new([1., 2.], den.clone());
assert_eq!(den, rf.den().as_slice());
source§

impl<T: Clone + PartialEq + Zero> Rf<T>

source

pub fn relative_degree(&self) -> i32

Calculate the relative degree between denominator and numerator.

Example
use automatica::{Inv, Rf};
let rf = Rf::new([1., 2.], [-4., 6., -2.]);
let expected = rf.relative_degree();
assert_eq!(expected, 1);
assert_eq!(rf.inv().relative_degree(), -1);
source§

impl<T> Rf<T>where T: Abs + Add<Output = T> + Clone + Copy + Div<Output = T> + EigenConst + Epsilon + Hypot + Inv<Output = T> + Max + Mul<Output = T> + Neg<Output = T> + One + PartialOrd + Pow<T> + Sign + Sqrt + Sub<Output = T> + Zero,

source

pub fn real_poles(&self) -> Option<Vec<T>>

Calculate the poles of the rational function

source

pub fn complex_poles(&self) -> Vec<(T, T)>

Calculate the poles of the rational function

source

pub fn real_zeros(&self) -> Option<Vec<T>>

Calculate the zeros of the rational function

source

pub fn complex_zeros(&self) -> Vec<(T, T)>

Calculate the zeros of the rational function

source§

impl<T> Rf<T>where T: Clone + Div<Output = T> + One + PartialEq + Zero,

source

pub fn normalize(&self) -> Self

Normalization of rational function. If the denominator is zero the same rational function is returned.

from:

       b_n*z^n + b_(n-1)*z^(n-1) + ... + b_1*z + b_0
G(z) = ---------------------------------------------
       a_n*z^n + a_(n-1)*z^(n-1) + ... + a_1*z + a_0

to:

       b'_n*z^n + b'_(n-1)*z^(n-1) + ... + b'_1*z + b'_0
G(z) = -------------------------------------------------
         z^n + a'_(n-1)*z^(n-1) + ... + a'_1*z + a'_0
Example
use automatica::Rf;
let rf = Rf::new([1., 2.], [-4., 6., -2.]);
let expected = Rf::new([-0.5, -1.], [2., -3., 1.]);
assert_eq!(expected, rf.normalize());
source

pub fn normalize_mut(&mut self)

In place normalization of rational function. If the denominator is zero no operation is done.

from:

       b_n*z^n + b_(n-1)*z^(n-1) + ... + b_1*z + b_0
G(z) = ---------------------------------------------
       a_n*z^n + a_(n-1)*z^(n-1) + ... + a_1*z + a_0

to:

       b'_n*z^n + b'_(n-1)*z^(n-1) + ... + b'_1*z + b'_0
G(z) = -------------------------------------------------
         z^n + a'_(n-1)*z^(n-1) + ... + a'_1*z + a'_0
Example
use automatica::Rf;
let mut rf = Rf::new([1., 2.], [-4., 6., -2.]);
rf.normalize_mut();
let expected = Rf::new([-0.5, -1.], [2., -3., 1.]);
assert_eq!(expected, rf);
source§

impl<T> Rf<T>where T: Clone + PartialEq,

source

pub fn eval_by_val<N>(&self, s: N) -> Nwhere N: Add<T, Output = N> + Clone + Div<Output = N> + Mul<Output = N> + Zero,

Evaluate the rational function.

Arguments
  • s - Value at which the rational function is evaluated.
Example
use automatica::{Complex as C, Rf};
let rf = Rf::new([1., 2., 3.], [-4., -3., 1.]);
assert_eq!(-8.5, rf.eval_by_val(3.));
assert_eq!(C::new(0.64, -0.98), rf.eval_by_val(C::new(0., 2.0)));
source§

impl<T> Rf<T>where T: Clone + PartialEq,

source

pub fn eval<N>(&self, s: &N) -> Nwhere N: Add<T, Output = N> + Clone + Div<Output = N> + Mul<N, Output = N> + Zero,

Evaluate the rational function.

Arguments
  • s - Value at which the rational function is evaluated.
Example
use automatica::{Complex as C, Rf};
let rf = Rf::new([1., 2., 3.], [-4., -3., 1.]);
assert_eq!(-8.5, rf.eval(&3.));
assert_eq!(C::new(0.64, -0.98), rf.eval(&C::new(0., 2.0)));

Trait Implementations§

source§

impl<T> Add<&Rf<T>> for &Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + One + PartialEq + Zero,

Implementation of rational function addition

§

type Output = Rf<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<T> Add<&T> for Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + PartialEq + Zero,

Implementation of rational function addition

§

type Output = Rf<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &T) -> Self

Performs the + operation. Read more
source§

impl<T> Add<Rf<T>> for Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + One + PartialEq + Zero,

Implementation of rational function addition

§

type Output = Rf<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
source§

impl<T> Add<T> for Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + PartialEq + Zero,

Implementation of rational function addition

§

type Output = Rf<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Self

Performs the + operation. Read more
source§

impl<T: Clone> Clone for Rf<T>

source§

fn clone(&self) -> Rf<T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Rf<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> Display for Rf<T>where T: Clone + Display + One + PartialEq + PartialOrd + Zero,

Implementation of rational function printing

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> Div<&Rf<T>> for &Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + One + PartialEq + Zero,

Implementation of rational function division

§

type Output = Rf<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
source§

impl<T> Div<Rf<T>> for Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + One + PartialEq + Zero,

Implementation of rational function division

§

type Output = Rf<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Self

Performs the / operation. Read more
source§

impl<T> Inv for &Rf<T>where T: Clone + PartialEq + Zero,

source§

fn inv(self) -> Self::Output

Compute the reciprocal of a rational function.

§

type Output = Rf<T>

Result of multiplicative inversion
source§

impl<T: Clone + PartialEq> Inv for Rf<T>

source§

fn inv(self) -> Self::Output

Compute the reciprocal of a rational function.

§

type Output = Rf<T>

Result of multiplicative inversion
source§

impl<T> Mul<&Rf<T>> for &Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + One + PartialEq + Zero,

Implementation of rational function multiplication

§

type Output = Rf<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl<T> Mul<&Rf<T>> for Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + One + PartialEq + Zero,

Implementation of rational function multiplication

§

type Output = Rf<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Rf<T>) -> Self

Performs the * operation. Read more
source§

impl<T> Mul<Rf<T>> for Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + One + PartialEq + Zero,

Implementation of rational function multiplication

§

type Output = Rf<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
source§

impl<T> Neg for &Rf<T>where T: Clone + Neg<Output = T> + PartialEq + Zero,

Implementation of rational function negation. Negative sign is transferred to the numerator.

§

type Output = Rf<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T> Neg for Rf<T>where T: Clone + Neg<Output = T> + PartialEq,

Implementation of rational function negation. Negative sign is transferred to the numerator.

§

type Output = Rf<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T: PartialEq> PartialEq<Rf<T>> for Rf<T>

source§

fn eq(&self, other: &Rf<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Sub<&Rf<T>> for &Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + Neg<Output = T> + PartialEq + Sub<Output = T> + Zero + One,

Implementation of rational function subtraction

§

type Output = Rf<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl<T> Sub<Rf<T>> for Rf<T>where T: Add<Output = T> + Clone + Mul<Output = T> + Neg<Output = T> + One + PartialEq + Sub<Output = T> + Zero,

Implementation of rational function subtraction

§

type Output = Rf<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
source§

impl<T> Zero for Rf<T>where T: Clone + One + PartialEq + Zero,

source§

fn zero() -> Self

Additive identity
source§

fn is_zero(&self) -> bool

Check if self is the additive identity
source§

impl<T> Zero for Rf<T>where T: Clone + One + PartialEq + Zero,

source§

fn zero() -> Self

Additive identity
source§

fn is_zero(&self) -> bool

Check if self is the additive identity
source§

impl<T> StructuralPartialEq for Rf<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Rf<T>where T: RefUnwindSafe,

§

impl<T> Send for Rf<T>where T: Send,

§

impl<T> Sync for Rf<T>where T: Sync,

§

impl<T> Unpin for Rf<T>where T: Unpin,

§

impl<T> UnwindSafe for Rf<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

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

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

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.