In the wise words of people far smarter than me (thank you kind people of the rustfully discord), a polynomial struct should be added to this repository.
An example implementation (all f64 might have to be replaced with generic variable to allow for floats and ints)
use crate::polynomials::{ascii_letters, Term, core::PolynomialError};
use crate::{eval_polynomial, parse_polynomial, parse_multivar, eval_multivar};
use std::str::FromStr;
struct Polynomial {
coefficents: Vec<f64>,
}
pub struct MultivariatePolynomial {
terms: Vec<Term>,
}
// inherient methods
impl Polynomial {
fn from(&self, coefficents: &str) -> Result<Self, PolynomialError> {
let parsed = parse_polynomial(coefficents)?;
Ok(Self {
coefficents: parsed,
})
}
fn solve(&self, point: f64) -> f64 {
eval_polynomial(point, &self.coefficents)
}
}
impl MultivariatePolynomial {
fn from(&self, coefficents: &str) -> Result<Self, PolynomialError> {
// change parse_multivar output from option to Result
let parsed = parse_multivar(coefficents)?; <- parameters need to be adjusted
Ok(Self {
terms: parsed,
})
}
fn solve(&self, point: f64) -> f64 {
// Need to create eval_multivar function
eval_multivar(point, &self.terms)
}
}
// trait implementation
impl FromStr for Polynomial {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
todo!("parse string into self or error")
}
}
impl FromStr for MultivariatePolynomial {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
todo!("parse string into self or error")
}
}
After creating the struct, it can be added as an output of parse_polynomial and parse_multivar and this struct should be the input of the bisection and nrm functions (replacing the string inputs that are parsed within the functions)
In the wise words of people far smarter than me (thank you kind people of the rustfully discord), a polynomial struct should be added to this repository.
An example implementation (all f64 might have to be replaced with generic variable to allow for floats and ints)
After creating the struct, it can be added as an output of
parse_polynomialandparse_multivarand this struct should be the input of thebisectionandnrmfunctions (replacing the string inputs that are parsed within the functions)