Ejemplo n.º 1
0
        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";
                }
            });
        }
Ejemplo n.º 2
0
        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;
                }
            });
        }