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

A struct for storing quadratic equations of the form f(x) = ax² + bx + c.

Implementations§

source§

impl<T: Copy + Clone + From<u8> + TryFrom<f64> + PartialEq + PartialOrd + NumTools<T> + Mul<Output = T> + Add<Output = T> + Sub<Output = T> + Div<Output = T> + Neg<Output = T>> QuadraticEquation<T>
where <T as TryFrom<f64>>::Error: Debug, f64: From<T>,

source

pub fn new() -> QuadraticEquation<T>

Create a new QuadraticEquation with the values a = 1, b = 0, c = 0.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, 0.0, 0.0);
f_x.get_vertex();
f_x.get_solutions();
 
assert_eq!(QuadraticEquation::new(), f_x);
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, 0.0, -1.5);
 
assert_eq!("1x^2 + 0x - 1.5", &f_x.to_string());
source

pub fn new_from_coefficients(a: T, b: T, c: T) -> QuadraticEquation<T>

Create a new QuadraticEquation from coefficients.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, 0.0, 0.0);
f_x.get_vertex();
f_x.get_solutions();
 
assert_eq!(QuadraticEquation::new(), f_x);
source

pub fn a(&self) -> T

Get a of a QuadraticEquation.

Returns

A T.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, -3.0);
 
assert_eq!(-2.0, f_x.b());
source

pub fn b(&self) -> T

Get b of a QuadraticEquation.

Returns

A T.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, -3.0);
 
assert_eq!(-2.0, f_x.b());
source

pub fn c(&self) -> T

Get c of a QuadraticEquation.

Returns

A T.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, -3.0);
 
assert_eq!(-3.0, f_x.c());
source

pub fn set_a(&mut self, value: T)

Set c of a QuadraticEquation.

Panics

Panics if value is zero.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, -3.0);
 
assert_eq!(1.0, f_x.a());
 
f_x.set_a(-1.0);
 
assert_eq!(-1.0, f_x.a());
source

pub fn set_b(&mut self, value: T)

Set b of a QuadraticEquation.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, -3.0);
 
assert_eq!(-2.0, f_x.b());
 
f_x.set_b(-1.0);
 
assert_eq!(-1.0, f_x.b());
source

pub fn set_c(&mut self, value: T)

Set c of a QuadraticEquation.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, -3.0);
 
assert_eq!(-3.0, f_x.c());
 
f_x.set_c(-1.0);
 
assert_eq!(-1.0, f_x.c());
source

pub fn get_solutions(&mut self) -> (Option<T>, Option<T>)

Get the solutions of a quadratic equation.

Returns

A (Option<T>, Option<T>).

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, -3.0);
 
assert_eq!((Some(3.0), Some(-1.0)), f_x.get_solutions());
source

pub fn intsect_with( &self, other: &QuadraticEquation<T> ) -> (Option<(T, T)>, Option<(T, T)>)

Get the intersection point(s) between self and other. Returns (None, None) if both arguments are equal.

Arguments
  • self.
  • other: &QuadraticEquation.
Returns

A (Option<(T, T)>, Option<(T, T)>) tuple.

use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, 2.0, 0.0);
let mut g_x = QuadraticEquation::new_from_coefficients(1.0, 2.0, 0.0);
let mut h_x = QuadraticEquation::new_from_coefficients(0.5, 1.0, 0.0);
 
assert_eq!( (None, None), f_x.intsect_with(&g_x));
assert_eq!( (Some( (0.0, 0.0) ), Some( (-2.0, 0.0) )), g_x.intsect_with(&h_x) );
source

pub fn intsect_with_linear( &self, other: &LinearEquation<T> ) -> (Option<(T, T)>, Option<(T, T)>)

Get the intersection point(s) between self and a linear equation if there is some.

Arguments
  • self.
  • other: &LinearEquation.
Returns

A (Option<(T, T)>, Option<(T, T)>) tuple.

use lib_rapid::math::equations::linear::LinearEquation;
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = LinearEquation::new(2.0, 2.0);
let mut g_x = QuadraticEquation::new_from_coefficients(1.2, 2.0, -2.0);
 
assert_eq!( ( Some((1.8257418583505536, 5.651483716701107)),
              Some((-1.8257418583505536, -1.6514837167011072)) ),
            g_x.intsect_with_linear(&f_x));
source

pub fn get_vertex(&mut self) -> (T, T)

Get the vertex (lowest or highest point) of a quadratic equation.

Returns

A (T, T).

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, 3.0);
 
assert_eq!((1.0, 2.0), f_x.get_vertex());
source

pub fn eval(&self, x: T) -> T

Get the value of a value x under the function of the QuadraticEquation.

Returns

A T.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
 
let f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, 3.0);
 
assert_eq!(2.0, f_x.eval(1.0));
source

pub fn get_derivative(&mut self) -> LinearEquation<T>

Get the derivative of a QuadraticEquation<T>. The derivative is the graph of the development of the slope for a given function self.

Returns

A LinearEquation<T>.

Examples
use lib_rapid::math::equations::quadratic::QuadraticEquation;
use lib_rapid::math::equations::linear::LinearEquation;
 
let mut f_x = QuadraticEquation::new_from_coefficients(1.0, -2.0, 3.0);
 
assert_eq!(LinearEquation::new(2.0, -2.0), f_x.get_derivative());

Trait Implementations§

source§

impl<T: Clone> Clone for QuadraticEquation<T>

source§

fn clone(&self) -> QuadraticEquation<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 QuadraticEquation<T>

source§

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

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

impl<T: Display + Neg<Output = T> + PartialOrd + From<u8> + Copy> Display for QuadraticEquation<T>

source§

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

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

impl<T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + PartialOrd + Neg<Output = T> + From<u8> + Copy + SubAssign + AddAssign + MulAssign + TryFrom<f64> + Display, const C: usize> From<Polynomial<C, T>> for QuadraticEquation<T>

source§

fn from(val: Polynomial<C, T>) -> Self

Converts to this type from the input type.
source§

impl<T: PartialEq> PartialEq for QuadraticEquation<T>

source§

fn eq(&self, other: &QuadraticEquation<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: Copy> Copy for QuadraticEquation<T>

source§

impl<T> StructuralPartialEq for QuadraticEquation<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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 T
where 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 T
where 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.