Browse Source

Start working on solving systems of eqns

solve-eqns
Alex Mikhalev 6 years ago
parent
commit
067f868222
  1. 37
      src/math/eqn.rs

37
src/math/eqn.rs

@ -123,6 +123,22 @@ impl Unknowns for Eqns { @@ -123,6 +123,22 @@ impl Unknowns for Eqns {
}
}
impl fmt::Display for Eqns {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{{ ");
let mut first = true;
for eq in &self.0 {
if first {
first = false;
} else {
write!(f, " && ")?;
}
write!(f, "{}", eq)?
}
write!(f, " }}")
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -155,7 +171,7 @@ mod tests { @@ -155,7 +171,7 @@ mod tests {
}
#[test]
fn test_solve() {
fn test_eqn_solve() {
use Expr::*;
let _ = env_logger::try_init();
let u1 = Unknown(1);
@ -232,4 +248,23 @@ mod tests { @@ -232,4 +248,23 @@ mod tests {
assert!(relative_eq!(const_expr(e.clone()).unwrap(), -9.));
}
#[test]
fn test_eqns_solve() {
use Expr::*;
let x = Unknown(1);
let y = Unknown(2);
let t1 = Unknown(3);
let t2 = Unknown(4);
let eqns = Eqns(vec![
Eqn::new(x.into(), t1 / 2.),
Eqn::new(y.into(), t1 / 2.),
Eqn::new(x.into(), Const(1.0) - t2 / 2.),
Eqn::new(y.into(), t2 / 2.),
]);
println!("eqns: {}", eqns);
let sol = eqns.solve(&[t1, t2]).unwrap();
}
}

Loading…
Cancel
Save