pub struct Equation {
pub text: String,
pub expression: Component,
}
Expand description
The equation struct containing the equation text and the parsed component.Component.
Various functions can be executed on this equation to solve it or it’s variables.
Fields§
§text: String
The equation in string form
expression: Component
The equation in a component tree
Implementations§
Source§impl Equation
impl Equation
Sourcepub fn new<T: Into<String>>(text: T) -> Equation
pub fn new<T: Into<String>>(text: T) -> Equation
Creates a new equation from an equation in string form
§Examples
let eq = calculi::Equation::new("a * sqrt(x + 1)");
Sourcepub fn derive(&self) -> Equation
pub fn derive(&self) -> Equation
Get the derivative of an equation
§Examples
let eq = calculi::Equation::new("x^sin(x)").derive();
assert_eq!(eq.text, "x ^ sin(x) * (cos(x) * ln(x) + sin(x) * 1 / x)");
Sourcepub fn solve_with<'a>(
&self,
vars_raw: impl IntoIterator<Item = (&'a str, f32)>,
) -> Component
pub fn solve_with<'a>( &self, vars_raw: impl IntoIterator<Item = (&'a str, f32)>, ) -> Component
Get the output of an equation with the given variable definitions
§Examples
let eq = calculi::Equation::new("a * sqrt(x + 1)");
assert_eq!(eq.solve_with(vec![("a", 2.0), ("x", 8.0)]).to_float().unwrap(), 6.0);
Sourcepub fn solve_for<'a>(
&self,
outcome: f32,
vars: impl IntoIterator<Item = (&'a str, f32)>,
) -> (Component, f32)
pub fn solve_for<'a>( &self, outcome: f32, vars: impl IntoIterator<Item = (&'a str, f32)>, ) -> (Component, f32)
Attempt to solve equation that contains an unknown variable Returns left over outcome and expression if solving failed
§Examples
let eq = calculi::Equation::new("a * sqrt(x + 1)");
let solved = eq.solve_for(9.0, vec![("x", 8.0)]);
assert_eq!(solved.0.to_string(), "a");
assert_eq!(solved.1, 3.0);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Equation
impl RefUnwindSafe for Equation
impl Send for Equation
impl Sync for Equation
impl Unpin for Equation
impl UnwindSafe for Equation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more