From 067f868222289d8e9433bc7b8a3f00705d22e100 Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Tue, 28 May 2019 10:59:19 -0700 Subject: [PATCH] Start working on solving systems of eqns --- src/math/eqn.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/math/eqn.rs b/src/math/eqn.rs index d54801d..fbbcb99 100644 --- a/src/math/eqn.rs +++ b/src/math/eqn.rs @@ -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 { } #[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 { 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(); + } + }