public PolynomialViewModel() { Solutions = @" Enter the equation like: e.g. x^2 + 2x + 1 as 1,2,1 8x^3 + 2 as 8,0,0,2 and click on Solve. "; EvaluateCommand = new DelegateCommand(() => { Evaluated = ""; try { var px = new Polynomial(Input.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .Select(Complex.Parse) .ToArray()); Equation = px.ToString(); Evaluated = px.Evaluate(Abscissa).ToString(); } catch { Evaluated = "Error"; } }); }
protected override void OnSolve() { Status = "Solving..."; Solutions = Equation = ""; Task.Run(() => { try { var px = new Polynomial(Input.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .Select(Complex.Parse) .ToArray()); var result = px.Roots.ToArray(); Solutions = result.Aggregate(string.Empty, (Current, Z) => Current + (Z + "\n")); Equation = px.ToString(); Status = result.Length == 1 ? "1 Root Found." : result.Length + " Roots Found."; } catch (Exception ex) { Status = ex.Message; } }); }