Example #1
0
        private void btnQuotientMcLaurin_Click(object sender, EventArgs e)
        {
            int  n;
            bool isNEntered = int.TryParse(nPolynomialTbx.Text, out n);

            if (isNEntered)
            {
                // First parse the expression, if any is entered.
                ParseAndPlotExpressions("Please enter an expression to use as basis for the MacLaurin Polynomial.");
                MacLaurinPolynomial macLaurinPolynomial = new MacLaurinPolynomial(expressionRoot.Copy(), n);
                // Create a graph of the highest order MacLaurin polynomial.
                Operand highestOrderPolynomial = macLaurinPolynomial.GetNthMacLaurinPolynomial(n);
                CreateGraphOfExpression(highestOrderPolynomial, "MacLaurinPolynomialQuotient");

                List <double> xRange = new List <double>();
                double        step   = 0.0001;

                for (double i = xMin; i <= xMax; i += step)
                {
                    xRange.Add(i);
                }

                List <List <double> > macLaurinValues = macLaurinPolynomial.CalculateMaclaurinPolynomials(xRange, n);
                for (int i = 0; i < macLaurinValues.Count; i++)
                {
                    CreateSeriesFromValues($"Polynomial {i}", xRange, macLaurinValues[i]);
                }
            }
            else
            {
                MessageBox.Show("Please enter a valid N for the nth order MacLaurin Polynomial.");
            }
        }
Example #2
0
        private void btnAnalyticalMcLaurin_Click(object sender, EventArgs e)
        {
            int  n;
            bool isNEntered = int.TryParse(nPolynomialTbx.Text, out n);

            if (isNEntered)
            {
                // First parse the expression, if any is entered.
                ParseAndPlotExpressions("Please enter an expression to use as basis for the MacLaurin Polynomial.");
                MacLaurinPolynomial macLaurinPolynomial = new MacLaurinPolynomial(expressionRoot.Copy(), n);
                // Create a graph of the highest order MacLaurin polynomial.
                Operand highestOrderPolynomial = macLaurinPolynomial.GetNthMacLaurinPolynomial(n);
                CreateGraphOfExpression(highestOrderPolynomial, "MacLaurinPolynomialAnalytically");

                // Plot all but the last which we do after the loop.
                for (int i = 0; i < n; i++)
                {
                    calculator = new CalculateForXHandler(macLaurinPolynomial.GetNthMacLaurinPolynomial(i).Calculate);
                    CreateChart($"MacLaurin Polynomial of degree {i}");
                }
                // Since we already used the simplified expression tree of the n-th order MacLaurin polynomial plot it after the loop.
                calculator = new CalculateForXHandler(highestOrderPolynomial.Calculate);
                CreateChart($"MacLaurin Polynomial of degree {n}");
            }
            else
            {
                MessageBox.Show("Please enter a valid N for the nth order MacLaurin Polynomial.");
            }
        }